formatting and fixes

This commit is contained in:
Scott E. Graves 2024-06-03 08:20:20 -05:00
parent 0e4c24a23d
commit 94d86a1c9f
37 changed files with 2742 additions and 2559 deletions

127
.clang-format Normal file
View File

@ -0,0 +1,127 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseTab: Never
...

10
.clang-tidy Normal file
View File

@ -0,0 +1,10 @@
---
Checks: '-*,clang-diagnostic-*,clang-analyzer-*,bugprone-*,concurrency-*,cppcoreguidelines-*,modernize-*,readability-*,-readability-redundant-access-specifiers,-readability-function-cognitive-complexity'
ExtraArgs: '-Wno-unknown-warning-option'
FormatStyle: none
HeaderFileExtensions: ['', 'h','hh','hpp','hxx']
HeaderFilterRegex: ''
ImplementationFileExtensions: ['c','cc','cpp','cxx']
User: 'scott.e.graves@protonmail.com'
WarningsAsErrors: ''
...

View File

@ -1,3 +1,13 @@
2024-06-03 Scott E. Graves
* bugfix: fixed compilation issues with GCC 14
* https://github.com/cubicdaiya/dtl/pull/22
* https://github.com/cubicdaiya/dtl/pull/18
* initialize variables to prevent warnings
* https://github.com/cubicdaiya/dtl/pull/16
* 1.21 released
2022-04-11 Tatsuhiko Kubo <cubicdaiya@gmail.com>
* bugfix: fixed invalid offset in unified format difference when difference is too large.

View File

@ -6,8 +6,8 @@
Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
@ -40,16 +40,15 @@
namespace dtl {
/**
/**
* diff class template
* sequence must support random_access_iterator.
*/
template <typename elem, typename sequence = vector< elem >, typename comparator = Compare< elem > >
class Diff
{
private :
dtl_typedefs(elem, sequence)
sequence A;
template <typename elem, typename sequence = vector<elem>,
typename comparator = Compare<elem>>
class Diff {
private:
dtl_typedefs(elem, sequence) sequence A;
sequence B;
size_t M;
size_t N;
@ -57,8 +56,8 @@ namespace dtl {
size_t offset;
long long *fp;
long long editDistance;
Lcs< elem > lcs;
Ses< elem > ses;
Lcs<elem> lcs;
Ses<elem> ses;
editPath path;
editPathCordinates pathCordinates;
bool swapped;
@ -69,150 +68,109 @@ namespace dtl {
comparator cmp;
long long ox;
long long oy;
public :
Diff () {}
Diff (const sequence& a,
const sequence& b) : A(a), B(b), ses(false) {
public:
Diff() {}
Diff(const sequence &a, const sequence &b) : A(a), B(b), ses(false) {
init();
}
Diff (const sequence& a,
const sequence& b,
bool deletesFirst) : A(a), B(b), ses(deletesFirst) {
Diff(const sequence &a, const sequence &b, bool deletesFirst)
: A(a), B(b), ses(deletesFirst) {
init();
}
Diff (const sequence& a,
const sequence& b,
const comparator& comp) : A(a), B(b), ses(false), cmp(comp) {
Diff(const sequence &a, const sequence &b, const comparator &comp)
: A(a), B(b), ses(false), cmp(comp) {
init();
}
Diff (const sequence& a,
const sequence& b,
bool deleteFirst,
const comparator& comp) : A(a), B(b), ses(deleteFirst), cmp(comp) {
Diff(const sequence &a, const sequence &b, bool deleteFirst,
const comparator &comp)
: A(a), B(b), ses(deleteFirst), cmp(comp) {
init();
}
~Diff() {}
long long getEditDistance () const {
return editDistance;
}
long long getEditDistance() const { return editDistance; }
Lcs< elem > getLcs () const {
return lcs;
}
Lcs<elem> getLcs() const { return lcs; }
elemVec getLcsVec () const {
return lcs.getSequence();
}
elemVec getLcsVec() const { return lcs.getSequence(); }
Ses< elem > getSes () const {
return ses;
}
Ses<elem> getSes() const { return ses; }
uniHunkVec getUniHunks () const {
return uniHunks;
}
uniHunkVec getUniHunks() const { return uniHunks; }
/* These should be deprecated */
bool isHuge () const {
return huge;
}
bool isHuge() const { return huge; }
void onHuge () {
this->huge = true;
}
void onHuge() { this->huge = true; }
void offHuge () {
this->huge = false;
}
void offHuge() { this->huge = false; }
bool isUnserious () const {
return trivial;
}
bool isUnserious() const { return trivial; }
void onUnserious () {
this->trivial = true;
}
void onUnserious() { this->trivial = true; }
void offUnserious () {
this->trivial = false;
}
void offUnserious() { this->trivial = false; }
void onOnlyEditDistance () {
this->editDistanceOnly = true;
}
void onOnlyEditDistance() { this->editDistanceOnly = true; }
/* These are the replacements for the above */
bool hugeEnabled () const {
return huge;
}
bool hugeEnabled() const { return huge; }
void enableHuge () {
this->huge = true;
}
void enableHuge() { this->huge = true; }
void disableHuge () {
this->huge = false;
}
void disableHuge() { this->huge = false; }
bool trivialEnabled () const {
return trivial;
}
bool trivialEnabled() const { return trivial; }
void enableTrivial () {
this->trivial = true;
}
void enableTrivial() { this->trivial = true; }
void disableTrivial () {
this->trivial = false;
}
void disableTrivial() { this->trivial = false; }
void editDistanceOnlyEnabled () {
this->editDistanceOnly = true;
}
void editDistanceOnlyEnabled() { this->editDistanceOnly = true; }
/**
* patching with Unified Format Hunks
*/
sequence uniPatch (const sequence& seq) {
sequence uniPatch(const sequence &seq) {
elemList seqLst(seq.begin(), seq.end());
sesElemVec shunk;
sesElemVec_iter vsesIt;
elemList_iter lstIt = seqLst.begin();
long long inc_dec_total = 0;
long long gap = 1;
for (uniHunkVec_iter it=uniHunks.begin();it!=uniHunks.end();++it) {
for (uniHunkVec_iter it = uniHunks.begin(); it != uniHunks.end(); ++it) {
joinSesVec(shunk, it->common[0]);
joinSesVec(shunk, it->change);
joinSesVec(shunk, it->common[1]);
it->a += inc_dec_total;
inc_dec_total += it->inc_dec_count;
for (long long i=0;i<it->a - gap;++i) {
for (long long i = 0; i < it->a - gap; ++i) {
++lstIt;
}
gap = it->a + it->b + it->inc_dec_count;
vsesIt = shunk.begin();
while (vsesIt!=shunk.end()) {
while (vsesIt != shunk.end()) {
switch (vsesIt->second.type) {
case SES_ADD :
case SES_ADD:
seqLst.insert(lstIt, vsesIt->first);
break;
case SES_DELETE :
case SES_DELETE:
if (lstIt != seqLst.end()) {
lstIt = seqLst.erase(lstIt);
}
break;
case SES_COMMON :
case SES_COMMON:
if (lstIt != seqLst.end()) {
++lstIt;
}
break;
default :
default:
// no fall-through
break;
}
@ -228,22 +186,23 @@ namespace dtl {
/**
* patching with Shortest Edit Script (SES)
*/
sequence patch (const sequence& seq) const {
sequence patch(const sequence &seq) const {
sesElemVec sesSeq = ses.getSequence();
elemList seqLst(seq.begin(), seq.end());
elemList_iter lstIt = seqLst.begin();
for (sesElemVec_iter sesIt=sesSeq.begin();sesIt!=sesSeq.end();++sesIt) {
for (sesElemVec_iter sesIt = sesSeq.begin(); sesIt != sesSeq.end();
++sesIt) {
switch (sesIt->second.type) {
case SES_ADD :
case SES_ADD:
seqLst.insert(lstIt, sesIt->first);
break;
case SES_DELETE :
case SES_DELETE:
lstIt = seqLst.erase(lstIt);
break;
case SES_COMMON :
case SES_COMMON:
++lstIt;
break;
default :
default:
// no through
break;
}
@ -254,8 +213,8 @@ namespace dtl {
/**
* compose Longest Common Subsequence and Shortest Edit Script.
* The algorithm implemented here is based on "An O(NP) Sequence Comparison Algorithm"
* described by Sun Wu, Udi Manber and Gene Myers
* The algorithm implemented here is based on "An O(NP) Sequence Comparison
* Algorithm" described by Sun Wu, Udi Manber and Gene Myers
*/
void compose() {
@ -272,17 +231,21 @@ namespace dtl {
ONP:
do {
++p;
for (long long k=-p;k<=static_cast<long long>(delta)-1;++k) {
fp[k+offset] = snake(k, fp[k-1+offset]+1, fp[k+1+offset]);
for (long long k = -p; k <= static_cast<long long>(delta) - 1; ++k) {
fp[k + offset] = snake(k, fp[k - 1 + offset] + 1, fp[k + 1 + offset]);
}
for (long long k=static_cast<long long>(delta)+p;k>=static_cast<long long>(delta)+1;--k) {
fp[k+offset] = snake(k, fp[k-1+offset]+1, fp[k+1+offset]);
for (long long k = static_cast<long long>(delta) + p;
k >= static_cast<long long>(delta) + 1; --k) {
fp[k + offset] = snake(k, fp[k - 1 + offset] + 1, fp[k + 1 + offset]);
}
fp[delta+offset] = snake(static_cast<long long>(delta), fp[delta-1+offset]+1, fp[delta+1+offset]);
} while (fp[delta+offset] != static_cast<long long>(N) && pathCordinates.size() < MAX_CORDINATES_SIZE);
fp[delta + offset] =
snake(static_cast<long long>(delta), fp[delta - 1 + offset] + 1,
fp[delta + 1 + offset]);
} while (fp[delta + offset] != static_cast<long long>(N) &&
pathCordinates.size() < MAX_CORDINATES_SIZE);
editDistance += static_cast<long long>(delta) + 2 * p;
long long r = path[delta+offset];
long long r = path[delta + offset];
P cordinate{};
editPathCordinates epc(0);
@ -292,7 +255,7 @@ namespace dtl {
return;
}
while(r != -1) {
while (r != -1) {
cordinate.x = pathCordinates[(size_t)r].x;
cordinate.y = pathCordinates[(size_t)r].y;
epc.push_back(cordinate);
@ -312,75 +275,73 @@ namespace dtl {
/**
* print difference between A and B as an SES
*/
template < typename stream >
void printSES (stream& out) const {
template <typename stream> void printSES(stream &out) const {
sesElemVec ses_v = ses.getSequence();
for_each(ses_v.begin(), ses_v.end(), ChangePrinter< sesElem, stream >(out));
for_each(ses_v.begin(), ses_v.end(), ChangePrinter<sesElem, stream>(out));
}
void printSES (ostream& out = cout) const {
printSES< ostream >(out);
}
void printSES(ostream &out = cout) const { printSES<ostream>(out); }
/**
* print differences given an SES
*/
template < typename stream >
static void printSES (const Ses< elem >& s, stream& out) {
template <typename stream>
static void printSES(const Ses<elem> &s, stream &out) {
sesElemVec ses_v = s.getSequence();
for_each(ses_v.begin(), ses_v.end(), ChangePrinter< sesElem, stream >(out));
for_each(ses_v.begin(), ses_v.end(), ChangePrinter<sesElem, stream>(out));
}
static void printSES (const Ses< elem >& s, ostream& out = cout) {
printSES< ostream >(s, out);
static void printSES(const Ses<elem> &s, ostream &out = cout) {
printSES<ostream>(s, out);
}
/**
* print difference between A and B as an SES with custom printer
*/
template < typename stream, template < typename SEET, typename STRT > class PT >
void printSES (stream& out) const {
sesElemVec ses_v = ses.getSequence ();
for_each (ses_v.begin (), ses_v.end(), PT < sesElem, stream > (out));
template <typename stream, template <typename SEET, typename STRT> class PT>
void printSES(stream &out) const {
sesElemVec ses_v = ses.getSequence();
for_each(ses_v.begin(), ses_v.end(), PT<sesElem, stream>(out));
}
/**
* store difference between A and B as an SES with custom storage
*/
template < typename storedData, template < typename SEET, typename STRT > class ST >
void storeSES(storedData& sd) const {
template <typename storedData,
template <typename SEET, typename STRT> class ST>
void storeSES(storedData &sd) const {
sesElemVec ses_v = ses.getSequence();
for_each(ses_v.begin(), ses_v.end(), ST < sesElem, storedData >(sd));
for_each(ses_v.begin(), ses_v.end(), ST<sesElem, storedData>(sd));
}
/**
* print difference between A and B in the Unified Format
*/
template < typename stream >
void printUnifiedFormat (stream& out) const {
for_each(uniHunks.begin(), uniHunks.end(), UniHunkPrinter< sesElem, stream >(out));
template <typename stream> void printUnifiedFormat(stream &out) const {
for_each(uniHunks.begin(), uniHunks.end(),
UniHunkPrinter<sesElem, stream>(out));
}
void printUnifiedFormat (ostream& out = cout) const {
printUnifiedFormat< ostream >(out);
void printUnifiedFormat(ostream &out = cout) const {
printUnifiedFormat<ostream>(out);
}
/**
* print unified format difference with given unified format hunks
*/
template < typename stream >
static void printUnifiedFormat (const uniHunkVec& hunks, stream& out) {
for_each(hunks.begin(), hunks.end(), UniHunkPrinter< sesElem >(out));
template <typename stream>
static void printUnifiedFormat(const uniHunkVec &hunks, stream &out) {
for_each(hunks.begin(), hunks.end(), UniHunkPrinter<sesElem>(out));
}
static void printUnifiedFormat (const uniHunkVec& hunks, ostream& out = cout) {
printUnifiedFormat< ostream >(hunks, out);
static void printUnifiedFormat(const uniHunkVec &hunks, ostream &out = cout) {
printUnifiedFormat<ostream>(hunks, out);
}
/**
* compose Unified Format Hunks from Shortest Edit Script
*/
void composeUnifiedHunks () {
void composeUnifiedHunks() {
sesElemVec common[2];
sesElemVec change;
sesElemVec ses_v = ses.getSequence();
@ -391,43 +352,49 @@ namespace dtl {
elemInfo einfo;
long long a, b, c, d; // @@ -a,b +c,d @@
long long inc_dec_count = 0;
uniHunk< sesElem > hunk;
uniHunk<sesElem> hunk;
sesElemVec adds;
sesElemVec deletes;
isMiddle = isAfter = false;
a = b = c = d = 0;
for (sesElemVec_iter it=ses_v.begin();it!=ses_v.end();++it, ++l_cnt) {
for (sesElemVec_iter it = ses_v.begin(); it != ses_v.end(); ++it, ++l_cnt) {
einfo = it->second;
switch (einfo.type) {
case SES_ADD :
case SES_ADD:
middle = 0;
++inc_dec_count;
adds.push_back(*it);
if (!isMiddle) isMiddle = true;
if (isMiddle) ++d;
if (!isMiddle)
isMiddle = true;
if (isMiddle)
++d;
if (l_cnt >= length) {
joinSesVec(change, deletes);
joinSesVec(change, adds);
isAfter = true;
}
break;
case SES_DELETE :
case SES_DELETE:
middle = 0;
--inc_dec_count;
deletes.push_back(*it);
if (!isMiddle) isMiddle = true;
if (isMiddle) ++b;
if (!isMiddle)
isMiddle = true;
if (isMiddle)
++b;
if (l_cnt >= length) {
joinSesVec(change, deletes);
joinSesVec(change, adds);
isAfter = true;
}
break;
case SES_COMMON :
++b;++d;
if (common[1].empty() && adds.empty() && deletes.empty() && change.empty()) {
case SES_COMMON:
++b;
++d;
if (common[1].empty() && adds.empty() && deletes.empty() &&
change.empty()) {
if (static_cast<long long>(common[0].size()) < DTL_CONTEXT_SIZE) {
if (a == 0 && c == 0) {
if (!wasSwapped()) {
@ -443,8 +410,10 @@ namespace dtl {
rotate(common[0].begin(), common[0].begin() + 1, common[0].end());
common[0].pop_back();
common[0].push_back(*it);
++a;++c;
--b;--d;
++a;
++c;
--b;
--d;
}
}
if (isMiddle && !isAfter) {
@ -459,7 +428,7 @@ namespace dtl {
deletes.clear();
}
break;
default :
default:
// no through
break;
}
@ -467,7 +436,8 @@ namespace dtl {
if (isAfter && !change.empty()) {
sesElemVec_iter cit = it;
long long cnt = 0;
for (long long i=0;i<DTL_SEPARATE_SIZE && (cit != ses_v.end());++i, ++cit) {
for (long long i = 0; i < DTL_SEPARATE_SIZE && (cit != ses_v.end());
++i, ++cit) {
if (cit->second.type == SES_COMMON) {
++cnt;
}
@ -482,15 +452,18 @@ namespace dtl {
rotate(common[0].begin(),
common[0].begin() + (size_t)c0size - DTL_SEPARATE_SIZE,
common[0].end());
for (long long i=0;i<c0size - DTL_SEPARATE_SIZE;++i) {
for (long long i = 0; i < c0size - DTL_SEPARATE_SIZE; ++i) {
common[0].pop_back();
}
a += c0size - DTL_SEPARATE_SIZE;
c += c0size - DTL_SEPARATE_SIZE;
}
if (a == 0) ++a;
if (c == 0) ++c;
if (wasSwapped()) swap(a, c);
if (a == 0)
++a;
if (c == 0)
++c;
if (wasSwapped())
swap(a, c);
hunk.a = a;
hunk.b = b;
hunk.c = c;
@ -515,11 +488,9 @@ namespace dtl {
/**
* compose ses from stream
*/
template <typename stream>
static Ses< elem > composeSesFromStream (stream& st)
{
template <typename stream> static Ses<elem> composeSesFromStream(stream &st) {
elem line;
Ses< elem > ret;
Ses<elem> ret;
long long x_idx, y_idx;
x_idx = y_idx = 1;
while (getline(st, line)) {
@ -540,11 +511,11 @@ namespace dtl {
return ret;
}
private :
private:
/**
* initialize
*/
void init () {
void init() {
M = distance(A.begin(), A.end());
N = distance(B.begin(), B.end());
if (M < N) {
@ -568,18 +539,25 @@ namespace dtl {
/**
* search shortest path and record the path
*/
long long snake(const long long& k, const long long& above, const long long& below) {
long long r = above > below ? path[(size_t)k-1+offset] : path[(size_t)k+1+offset];
long long snake(const long long &k, const long long &above,
const long long &below) {
long long r = above > below ? path[(size_t)k - 1 + offset]
: path[(size_t)k + 1 + offset];
long long y = max(above, below);
long long x = y - k;
while ((size_t)x < M && (size_t)y < N && (swapped ? cmp.impl(B[(size_t)y], A[(size_t)x]) : cmp.impl(A[(size_t)x], B[(size_t)y]))) {
++x;++y;
while ((size_t)x < M && (size_t)y < N &&
(swapped ? cmp.impl(B[(size_t)y], A[(size_t)x])
: cmp.impl(A[(size_t)x], B[(size_t)y]))) {
++x;
++y;
}
path[(size_t)k+offset] = static_cast<long long>(pathCordinates.size());
path[(size_t)k + offset] = static_cast<long long>(pathCordinates.size());
if (!editDistanceOnly) {
P p;
p.x = x;p.y = y;p.k = r;
p.x = x;
p.y = y;
p.k = r;
pathCordinates.push_back(p);
}
return y;
@ -588,7 +566,7 @@ namespace dtl {
/**
* record SES and LCS
*/
bool recordSequence (const editPathCordinates& v) {
bool recordSequence(const editPathCordinates &v) {
sequence_const_iter x(A.begin());
sequence_const_iter y(B.begin());
long long x_idx, y_idx; // line number for Unified Format
@ -596,8 +574,8 @@ namespace dtl {
bool complete = false;
x_idx = y_idx = 1;
px_idx = py_idx = 0;
for (size_t i=v.size()-1;!complete;--i) {
while(px_idx < v[i].x || py_idx < v[i].y) {
for (size_t i = v.size() - 1; !complete; --i) {
while (px_idx < v[i].x || py_idx < v[i].y) {
if (v[i].y - v[i].x > py_idx - px_idx) {
if (!wasSwapped()) {
ses.addSequence(*y, 0, y_idx + oy, SES_ADD);
@ -632,10 +610,12 @@ namespace dtl {
++py_idx;
}
}
if (i == 0) complete = true;
if (i == 0)
complete = true;
}
if (x_idx > static_cast<long long>(M) && y_idx > static_cast<long long>(N)) {
if (x_idx > static_cast<long long>(M) &&
y_idx > static_cast<long long>(N)) {
// all recording succeeded
} else {
// trivial difference
@ -673,8 +653,9 @@ namespace dtl {
/**
* record odd sequence in SES
*/
void inline recordOddSequence (long long idx, long long length, sequence_const_iter it, const edit_t et) {
while(idx < length){
void inline recordOddSequence(long long idx, long long length,
sequence_const_iter it, const edit_t et) {
while (idx < length) {
ses.addSequence(*it, idx, 0, et);
++it;
++idx;
@ -687,9 +668,9 @@ namespace dtl {
/**
* join SES vectors
*/
void inline joinSesVec (sesElemVec& s1, sesElemVec& s2) const {
void inline joinSesVec(sesElemVec &s1, sesElemVec &s2) const {
if (!s2.empty()) {
for (sesElemVec_iter vit=s2.begin();vit!=s2.end();++vit) {
for (sesElemVec_iter vit = s2.begin(); vit != s2.end(); ++vit) {
s1.push_back(*vit);
}
}
@ -698,11 +679,8 @@ namespace dtl {
/**
* check if the sequences have been swapped
*/
bool inline wasSwapped () const {
return swapped;
}
};
}
bool inline wasSwapped() const { return swapped; }
};
} // namespace dtl
#endif // DTL_DIFF_H

View File

@ -6,8 +6,8 @@
Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
@ -40,47 +40,40 @@
namespace dtl {
/**
/**
* diff3 class template
* sequence must support random_access_iterator.
*/
template <typename elem, typename sequence = vector< elem >, typename comparator = Compare< elem > >
class Diff3
{
private:
dtl_typedefs(elem, sequence)
sequence A;
template <typename elem, typename sequence = vector<elem>,
typename comparator = Compare<elem>>
class Diff3 {
private:
dtl_typedefs(elem, sequence) sequence A;
sequence B;
sequence C;
sequence S;
Diff< elem, sequence, comparator > diff_ba;
Diff< elem, sequence, comparator > diff_bc;
Diff<elem, sequence, comparator> diff_ba;
Diff<elem, sequence, comparator> diff_bc;
bool conflict;
elem csepabegin;
elem csepa;
elem csepaend;
public :
Diff3 () {}
Diff3 (const sequence& a,
const sequence& b,
const sequence& c) : A(a), B(b), C(c),
diff_ba(b, a), diff_bc(b, c),
conflict(false) {}
~Diff3 () {}
public:
Diff3() {}
Diff3(const sequence &a, const sequence &b, const sequence &c)
: A(a), B(b), C(c), diff_ba(b, a), diff_bc(b, c), conflict(false) {}
bool isConflict () const {
return conflict;
}
~Diff3() {}
sequence getMergedSequence () const {
return S;
}
bool isConflict() const { return conflict; }
sequence getMergedSequence() const { return S; }
/**
* merge changes B and C into A
*/
bool merge () {
bool merge() {
if (diff_ba.getEditDistance() == 0) { // A == B
if (diff_bc.getEditDistance() == 0) { // A == B == C
S = B;
@ -105,19 +98,19 @@ namespace dtl {
/**
* compose differences
*/
void compose () {
void compose() {
diff_ba.compose();
diff_bc.compose();
}
private :
private:
/**
* merge implementation
*/
sequence merge_ () {
sequence merge_() {
elemVec seq;
Ses< elem > ses_ba = diff_ba.getSes();
Ses< elem > ses_bc = diff_bc.getSes();
Ses<elem> ses_ba = diff_ba.getSes();
Ses<elem> ses_bc = diff_bc.getSes();
sesElemVec ses_ba_v = ses_ba.getSequence();
sesElemVec ses_bc_v = ses_bc.getSequence();
sesElemVec_iter ba_it = ses_ba_v.begin();
@ -127,23 +120,24 @@ namespace dtl {
while (!isEnd(ba_end, ba_it) || !isEnd(bc_end, bc_it)) {
while (true) {
if (!isEnd(ba_end, ba_it) &&
!isEnd(bc_end, bc_it) &&
ba_it->first == bc_it->first &&
ba_it->second.type == SES_COMMON &&
if (!isEnd(ba_end, ba_it) && !isEnd(bc_end, bc_it) &&
ba_it->first == bc_it->first && ba_it->second.type == SES_COMMON &&
bc_it->second.type == SES_COMMON) {
// do nothing
} else {
break;
}
if (!isEnd(ba_end, ba_it)) seq.push_back(ba_it->first);
else if (!isEnd(bc_end, bc_it)) seq.push_back(bc_it->first);
if (!isEnd(ba_end, ba_it))
seq.push_back(ba_it->first);
else if (!isEnd(bc_end, bc_it))
seq.push_back(bc_it->first);
forwardUntilEnd(ba_end, ba_it);
forwardUntilEnd(bc_end, bc_it);
}
if (isEnd(ba_end, ba_it) || isEnd(bc_end, bc_it)) break;
if ( ba_it->second.type == SES_COMMON
&& bc_it->second.type == SES_DELETE) {
if (isEnd(ba_end, ba_it) || isEnd(bc_end, bc_it))
break;
if (ba_it->second.type == SES_COMMON &&
bc_it->second.type == SES_DELETE) {
forwardUntilEnd(ba_end, ba_it);
forwardUntilEnd(bc_end, bc_it);
} else if (ba_it->second.type == SES_COMMON &&
@ -205,9 +199,9 @@ namespace dtl {
/**
* join elem vectors
*/
void inline joinElemVec (elemVec& s1, elemVec& s2) const {
void inline joinElemVec(elemVec &s1, elemVec &s2) const {
if (!s2.empty()) {
for (elemVec_iter vit=s2.begin();vit!=s2.end();++vit) {
for (elemVec_iter vit = s2.begin(); vit != s2.end(); ++vit) {
s1.push_back(*vit);
}
}
@ -217,7 +211,7 @@ namespace dtl {
* check if sequence is at end
*/
template <typename T_iter>
bool inline isEnd (const T_iter& end, const T_iter& it) const {
bool inline isEnd(const T_iter &end, const T_iter &it) const {
return it == end ? true : false;
}
@ -225,21 +219,23 @@ namespace dtl {
* increment iterator until iterator is at end
*/
template <typename T_iter>
void inline forwardUntilEnd (const T_iter& end, T_iter& it) const {
if (!isEnd(end, it)) ++it;
void inline forwardUntilEnd(const T_iter &end, T_iter &it) const {
if (!isEnd(end, it))
++it;
}
/**
* add elements whose SES's type is ADD
*/
void inline addDecentSequence (const sesElemVec_iter& end, sesElemVec_iter& it, elemVec& seq) const {
void inline addDecentSequence(const sesElemVec_iter &end, sesElemVec_iter &it,
elemVec &seq) const {
while (!isEnd(end, it)) {
if (it->second.type == SES_ADD) seq.push_back(it->first);
if (it->second.type == SES_ADD)
seq.push_back(it->first);
++it;
}
}
};
}
};
} // namespace dtl
#endif // DTL_DIFF3_H

View File

@ -6,8 +6,8 @@
Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
@ -40,16 +40,14 @@
namespace dtl {
/**
/**
* Longest Common Subsequence template class
*/
template <typename elem>
class Lcs : public Sequence< elem >
{
public :
Lcs () {}
~Lcs () {}
};
}
template <typename elem> class Lcs : public Sequence<elem> {
public:
Lcs() {}
~Lcs() {}
};
} // namespace dtl
#endif // DTL_LCS_H

View File

@ -6,8 +6,8 @@
Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
@ -40,26 +40,21 @@
namespace dtl {
/**
/**
* sequence class template
*/
template <typename elem>
class Sequence
{
public :
typedef vector< elem > elemVec;
Sequence () {}
virtual ~Sequence () {}
template <typename elem> class Sequence {
public:
typedef vector<elem> elemVec;
Sequence() {}
virtual ~Sequence() {}
elemVec getSequence () const {
return sequence;
}
void addSequence (elem e) {
sequence.push_back(e);
}
protected :
elemVec getSequence() const { return sequence; }
void addSequence(elem e) { sequence.push_back(e); }
protected:
elemVec sequence;
};
}
};
} // namespace dtl
#endif // DTL_SEQUENCE_H

View File

@ -6,8 +6,8 @@
Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
@ -40,47 +40,39 @@
namespace dtl {
/**
/**
* Shortest Edit Script template class
*/
template <typename elem>
class Ses : public Sequence< elem >
{
private :
typedef pair< elem, elemInfo > sesElem;
typedef vector< sesElem > sesElemVec;
public :
template <typename elem> class Ses : public Sequence<elem> {
private:
typedef pair<elem, elemInfo> sesElem;
typedef vector<sesElem> sesElemVec;
Ses () : onlyAdd(true), onlyDelete(true), onlyCopy(true), deletesFirst(false) {
public:
Ses() : onlyAdd(true), onlyDelete(true), onlyCopy(true), deletesFirst(false) {
nextDeleteIdx = 0;
}
Ses (bool moveDel) : onlyAdd(true), onlyDelete(true), onlyCopy(true), deletesFirst(moveDel) {
Ses(bool moveDel)
: onlyAdd(true), onlyDelete(true), onlyCopy(true), deletesFirst(moveDel) {
nextDeleteIdx = 0;
}
~Ses () {}
~Ses() {}
bool isOnlyAdd () const {
return onlyAdd;
}
bool isOnlyAdd() const { return onlyAdd; }
bool isOnlyDelete () const {
return onlyDelete;
}
bool isOnlyDelete() const { return onlyDelete; }
bool isOnlyCopy () const {
return onlyCopy;
}
bool isOnlyCopy() const { return onlyCopy; }
bool isOnlyOneOperation () const {
bool isOnlyOneOperation() const {
return isOnlyAdd() || isOnlyDelete() || isOnlyCopy();
}
bool isChange () const {
return !onlyCopy;
}
bool isChange() const { return !onlyCopy; }
using Sequence< elem >::addSequence;
void addSequence (elem e, long long beforeIdx, long long afterIdx, const edit_t type) {
using Sequence<elem>::addSequence;
void addSequence(elem e, long long beforeIdx, long long afterIdx,
const edit_t type) {
elemInfo info;
info.beforeIdx = beforeIdx;
info.afterIdx = afterIdx;
@ -116,17 +108,16 @@ namespace dtl {
}
}
sesElemVec getSequence () const {
return sequence;
}
private :
sesElemVec getSequence() const { return sequence; }
private:
sesElemVec sequence;
bool onlyAdd;
bool onlyDelete;
bool onlyCopy;
bool deletesFirst;
size_t nextDeleteIdx;
};
}
};
} // namespace dtl
#endif // DTL_SES_H

View File

@ -6,8 +6,8 @@
Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
@ -36,12 +36,12 @@
#ifndef DTL_H
#define DTL_H
#include "variables.hpp"
#include "functors.hpp"
#include "Sequence.hpp"
#include "Lcs.hpp"
#include "Ses.hpp"
#include "Diff.hpp"
#include "Diff3.hpp"
#include "Lcs.hpp"
#include "Sequence.hpp"
#include "Ses.hpp"
#include "functors.hpp"
#include "variables.hpp"
#endif // DTL_H

View File

@ -6,8 +6,8 @@
Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
@ -40,47 +40,44 @@
namespace dtl {
/**
/**
* printer class template
*/
template <typename sesElem, typename stream = ostream >
class Printer
{
public :
Printer () : out_(cout) {}
Printer (stream& out) : out_(out) {}
virtual ~Printer () {}
virtual void operator() (const sesElem& se) const = 0;
protected :
stream& out_;
};
template <typename sesElem, typename stream = ostream> class Printer {
public:
Printer() : out_(cout) {}
Printer(stream &out) : out_(out) {}
virtual ~Printer() {}
virtual void operator()(const sesElem &se) const = 0;
/**
protected:
stream &out_;
};
/**
* common element printer class template
*/
template <typename sesElem, typename stream = ostream >
class CommonPrinter : public Printer < sesElem, stream >
{
public :
CommonPrinter () : Printer < sesElem, stream > () {}
CommonPrinter (stream& out) : Printer < sesElem, stream > (out) {}
~CommonPrinter () {}
void operator() (const sesElem& se) const {
template <typename sesElem, typename stream = ostream>
class CommonPrinter : public Printer<sesElem, stream> {
public:
CommonPrinter() : Printer<sesElem, stream>() {}
CommonPrinter(stream &out) : Printer<sesElem, stream>(out) {}
~CommonPrinter() {}
void operator()(const sesElem &se) const {
this->out_ << SES_MARK_COMMON << se.first << endl;
}
};
};
/**
/**
* ses element printer class template
*/
template <typename sesElem, typename stream = ostream >
class ChangePrinter : public Printer < sesElem, stream >
{
public :
ChangePrinter () : Printer < sesElem, stream > () {}
ChangePrinter (stream& out) : Printer < sesElem, stream > (out) {}
~ChangePrinter () {}
void operator() (const sesElem& se) const {
template <typename sesElem, typename stream = ostream>
class ChangePrinter : public Printer<sesElem, stream> {
public:
ChangePrinter() : Printer<sesElem, stream>() {}
ChangePrinter(stream &out) : Printer<sesElem, stream>(out) {}
~ChangePrinter() {}
void operator()(const sesElem &se) const {
switch (se.second.type) {
case SES_ADD:
this->out_ << SES_MARK_ADD << se.first << endl;
@ -93,59 +90,57 @@ namespace dtl {
break;
}
}
};
};
/**
/**
* unified format element printer class template
*/
template <typename sesElem, typename stream = ostream >
class UniHunkPrinter
{
public :
UniHunkPrinter () : out_(cout) {}
UniHunkPrinter (stream& out) : out_(out) {}
~UniHunkPrinter () {}
void operator() (const uniHunk< sesElem >& hunk) const {
template <typename sesElem, typename stream = ostream> class UniHunkPrinter {
public:
UniHunkPrinter() : out_(cout) {}
UniHunkPrinter(stream &out) : out_(out) {}
~UniHunkPrinter() {}
void operator()(const uniHunk<sesElem> &hunk) const {
out_ << "@@"
<< " -" << hunk.a << "," << hunk.b
<< " +" << hunk.c << "," << hunk.d
<< " -" << hunk.a << "," << hunk.b << " +" << hunk.c << "," << hunk.d
<< " @@" << endl;
for_each(hunk.common[0].begin(), hunk.common[0].end(), CommonPrinter< sesElem, stream >(out_));
for_each(hunk.change.begin(), hunk.change.end(), ChangePrinter< sesElem, stream >(out_));
for_each(hunk.common[1].begin(), hunk.common[1].end(), CommonPrinter< sesElem, stream >(out_));
for_each(hunk.common[0].begin(), hunk.common[0].end(),
CommonPrinter<sesElem, stream>(out_));
for_each(hunk.change.begin(), hunk.change.end(),
ChangePrinter<sesElem, stream>(out_));
for_each(hunk.common[1].begin(), hunk.common[1].end(),
CommonPrinter<sesElem, stream>(out_));
}
private :
stream& out_;
};
/**
private:
stream &out_;
};
/**
* storage class template
*/
template <typename sesElem, typename storedData >
class Storage
{
public:
Storage(storedData& sd) : storedData_(sd) {}
template <typename sesElem, typename storedData> class Storage {
public:
Storage(storedData &sd) : storedData_(sd) {}
virtual ~Storage() {}
virtual void operator() (const sesElem& se) const = 0;
protected:
storedData& storedData_;
};
virtual void operator()(const sesElem &se) const = 0;
/**
protected:
storedData &storedData_;
};
/**
* compare class template
*/
template <typename elem>
class Compare
{
public :
Compare () {}
virtual ~Compare () {}
virtual inline bool impl (const elem& e1, const elem& e2) const {
template <typename elem> class Compare {
public:
Compare() {}
virtual ~Compare() {}
virtual inline bool impl(const elem &e1, const elem &e2) const {
return e1 == e2;
}
};
}
};
} // namespace dtl
#endif // DTL_FUNCTORS_H

View File

@ -6,8 +6,8 @@
Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
@ -38,97 +38,97 @@
#ifndef DTL_VARIABLES_H
#define DTL_VARIABLES_H
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <iostream>
#include <list>
#include <string>
#include <vector>
namespace dtl {
using std::vector;
using std::string;
using std::pair;
using std::ostream;
using std::list;
using std::for_each;
using std::distance;
using std::fill;
using std::cout;
using std::endl;
using std::rotate;
using std::swap;
using std::max;
using std::cout;
using std::distance;
using std::endl;
using std::fill;
using std::for_each;
using std::list;
using std::max;
using std::ostream;
using std::pair;
using std::rotate;
using std::string;
using std::swap;
using std::vector;
/**
/**
* version string
*/
const string version = "1.20";
const string version = "1.21";
/**
/**
* type of edit for SES
*/
typedef int edit_t;
const edit_t SES_DELETE = -1;
const edit_t SES_COMMON = 0;
const edit_t SES_ADD = 1;
typedef int edit_t;
const edit_t SES_DELETE = -1;
const edit_t SES_COMMON = 0;
const edit_t SES_ADD = 1;
/**
/**
* mark of SES
*/
#define SES_MARK_DELETE "-"
#define SES_MARK_COMMON " "
#define SES_MARK_ADD "+"
/**
/**
* info for Unified Format
*/
typedef struct eleminfo {
typedef struct eleminfo {
long long beforeIdx; // index of prev sequence
long long afterIdx; // index of after sequence
edit_t type; // type of edit(Add, Delete, Common)
bool operator==(const eleminfo& other) const{
return (this->beforeIdx == other.beforeIdx && this->afterIdx == other.afterIdx && this->type == other.type);
bool operator==(const eleminfo &other) const {
return (this->beforeIdx == other.beforeIdx &&
this->afterIdx == other.afterIdx && this->type == other.type);
}
} elemInfo;
} elemInfo;
const long long DTL_SEPARATE_SIZE = 3;
const long long DTL_CONTEXT_SIZE = 3;
const long long DTL_SEPARATE_SIZE = 3;
const long long DTL_CONTEXT_SIZE = 3;
/**
/**
* cordinate for registering route
*/
typedef struct Point {
typedef struct Point {
long long x; // x cordinate
long long y; // y cordinate
long long k; // vertex
} P;
} P;
/**
/**
* limit of cordinate size
*/
const unsigned long long MAX_CORDINATES_SIZE = 2000000;
const unsigned long long MAX_CORDINATES_SIZE = 2000000;
typedef vector< long long > editPath;
typedef vector< P > editPathCordinates;
typedef vector<long long> editPath;
typedef vector<P> editPathCordinates;
/**
/**
* Structure of Unified Format Hunk
*/
template <typename sesElem>
struct uniHunk {
template <typename sesElem> struct uniHunk {
long long a, b, c, d; // @@ -a,b +c,d @@
vector< sesElem > common[2]; // anteroposterior commons on changes
vector< sesElem > change; // changes
vector<sesElem> common[2]; // anteroposterior commons on changes
vector<sesElem> change; // changes
long long inc_dec_count; // count of increace and decrease
};
};
#define dtl_typedefs(elem, sequence) \
typedef pair< elem, elemInfo > sesElem; \
typedef vector< sesElem > sesElemVec; \
typedef vector< uniHunk< sesElem > > uniHunkVec; \
typedef list< elem > elemList; \
typedef vector< elem > elemVec; \
typedef pair<elem, elemInfo> sesElem; \
typedef vector<sesElem> sesElemVec; \
typedef vector<uniHunk<sesElem>> uniHunkVec; \
typedef list<elem> elemList; \
typedef vector<elem> elemVec; \
typedef typename uniHunkVec::iterator uniHunkVec_iter; \
typedef typename sesElemVec::iterator sesElemVec_iter; \
typedef typename elemList::iterator elemList_iter; \
@ -136,7 +136,6 @@ namespace dtl {
typedef typename sequence::const_iterator sequence_const_iter; \
typedef typename elemVec::iterator elemVec_iter;
}
} // namespace dtl
#endif // DTL_VARIABLES_H

View File

@ -1,14 +1,14 @@
#include <dtl/dtl.hpp>
#include "common.hpp"
#include <dtl/dtl.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <iostream>
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
#include <vector>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif // HAVE_UNISTD_H
@ -18,11 +18,10 @@ using namespace std;
using dtl::Diff;
typedef unsigned char elem;
typedef vector< elem > sequence;
typedef vector<elem> sequence;
static int create_byte_seq(const char *fs, sequence& seq);
static int create_byte_seq(const char *fs, sequence& seq)
{
static int create_byte_seq(const char *fs, sequence &seq);
static int create_byte_seq(const char *fs, sequence &seq) {
int fd;
int siz;
elem buf[BUFSIZ];
@ -31,7 +30,7 @@ static int create_byte_seq(const char *fs, sequence& seq)
return -1;
}
while ((siz = read(fd, buf, sizeof(buf))) > 0) {
for (int i=0;i<siz;++i) {
for (int i = 0; i < siz; ++i) {
seq.push_back(buf[i]);
}
}
@ -44,8 +43,7 @@ static int create_byte_seq(const char *fs, sequence& seq)
return 0;
}
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
if (isFewArgs(argc)) {
cerr << "Too few arguments." << endl;
@ -60,7 +58,7 @@ int main(int argc, char *argv[])
create_byte_seq(fs1.c_str(), seq1);
create_byte_seq(fs2.c_str(), seq2);
Diff< elem, sequence > d(seq1, seq2);
Diff<elem, sequence> d(seq1, seq2);
d.compose();
if (d.getEditDistance() == 0) {

View File

@ -1,7 +1,7 @@
#include "common.hpp"
bool isFileExist (string& fs) {
bool isFileExist(string &fs) {
FILE *fp;
if ((fp = fopen(fs.c_str(), "r")) == NULL) {
return false;
@ -10,11 +10,10 @@ bool isFileExist (string& fs) {
return true;
}
bool isFewArgs (int argc, int limit) {
bool isFewArgs(int argc, int limit) {
bool ret = false;
if (argc < limit) {
ret = true;
}
return ret;
}

View File

@ -2,12 +2,12 @@
#ifndef DTL_EXAMPLE_COMMON_H
#define DTL_EXAMPLE_COMMON_H
#include <string>
#include <cstdio>
#include <string>
using namespace std;
bool isFileExist (string& fs);
bool isFewArgs (int argc, int limit = 3);
bool isFileExist(string &fs);
bool isFewArgs(int argc, int limit = 3);
#endif

View File

@ -1,17 +1,17 @@
#include <dtl/dtl.hpp>
#include "common.hpp"
#include <cassert>
#include <dtl/dtl.hpp>
#include <fstream>
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <cassert>
using namespace std;
using dtl::Diff;
int main(int argc, char *argv[]){
int main(int argc, char *argv[]) {
if (isFewArgs(argc)) {
cerr << "Too few arguments." << endl;
@ -37,7 +37,7 @@ int main(int argc, char *argv[]){
}
typedef string elem;
typedef vector< elem > sequence;
typedef vector<elem> sequence;
ifstream Aifs(A.c_str());
ifstream Bifs(B.c_str());
@ -45,14 +45,14 @@ int main(int argc, char *argv[]){
sequence ALines, BLines;
ostringstream ossLine, ossInfo;
while(getline(Aifs, buf)){
while (getline(Aifs, buf)) {
ALines.push_back(buf);
}
while(getline(Bifs, buf)){
while (getline(Bifs, buf)) {
BLines.push_back(buf);
}
Diff< elem > d(ALines, BLines);
Diff<elem> d(ALines, BLines);
d.compose();
sequence s1 = ALines;

View File

@ -1,33 +1,33 @@
#include <dtl/dtl.hpp>
#include <iostream>
#include <vector>
#include <dtl/dtl.hpp>
using namespace std;
using dtl::Diff;
int main(int, char**){
int main(int, char **) {
int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int b[] = {3, 5, 1, 4, 5, 1, 7, 9, 6, 10};
int asiz = sizeof(a) / sizeof(int);
int bsiz = sizeof(b) / sizeof(int);
for (int i=0;i<asiz;++i) {
for (int i = 0; i < asiz; ++i) {
cout << a[i] << " ";
}
cout << endl;
for (int i=0;i<bsiz;++i) {
for (int i = 0; i < bsiz; ++i) {
cout << b[i] << " ";
}
cout << endl;
typedef int elem;
typedef vector< int > sequence;
typedef vector<int> sequence;
sequence A(&a[0], &a[asiz]);
sequence B(&b[0], &b[bsiz]);
Diff< elem > d(A, B);
Diff<elem> d(A, B);
d.compose();
// editDistance
@ -36,7 +36,7 @@ int main(int, char**){
// Longest Common Subsequence
sequence lcs_v = d.getLcsVec();
cout << "LCS: ";
for (sequence::iterator vit=lcs_v.begin();vit!=lcs_v.end();++vit) {
for (sequence::iterator vit = lcs_v.begin(); vit != lcs_v.end(); ++vit) {
cout << *vit << " ";
}
cout << endl;

View File

@ -1,14 +1,14 @@
#include <cassert>
#include <dtl/dtl.hpp>
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
using dtl::Diff3;
int main(int, char**) {
int main(int, char **) {
int a[10] = {1, 2, 3, 4, 5, 6, 7, 3, 9, 10};
int b[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
@ -16,28 +16,28 @@ int main(int, char**) {
int answer[10] = {1, 2, 3, 9, 5, 6, 7, 3, 9, 10};
cout << "a:";
for (int i=0;i<10;++i) {
for (int i = 0; i < 10; ++i) {
cout << a[i] << " ";
}
cout << endl;
cout << "b:";
for (int i=0;i<10;++i) {
for (int i = 0; i < 10; ++i) {
cout << b[i] << " ";
}
cout << endl;
cout << "c:";
for (int i=0;i<10;++i) {
for (int i = 0; i < 10; ++i) {
cout << c[i] << " ";
}
cout << endl;
typedef int elem;
typedef vector< int > sequence;
typedef vector<int> sequence;
sequence A(&a[0], &a[10]);
sequence B(&b[0], &b[10]);
sequence C(&c[0], &c[10]);
sequence Answer(&answer[0], &answer[10]);
Diff3< elem > diff3(A, B, C);
Diff3<elem> diff3(A, B, C);
diff3.compose();
if (!diff3.merge()) {
cerr << "conflict." << endl;
@ -45,7 +45,7 @@ int main(int, char**) {
}
sequence s = diff3.getMergedSequence();
cout << "s:";
for (sequence::iterator it=s.begin();it!=s.end();++it) {
for (sequence::iterator it = s.begin(); it != s.end(); ++it) {
cout << *it << " ";
}
cout << endl;

View File

@ -1,9 +1,9 @@
#include <dtl/dtl.hpp>
#include "common.hpp"
#include <cassert>
#include <dtl/dtl.hpp>
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
@ -22,7 +22,7 @@ int main(int argc, char *argv[]) {
sequence A(argv[1]);
sequence B(argv[2]);
Diff< elem, sequence > d(A, B);
Diff<elem, sequence> d(A, B);
d.compose();
sequence s1(A);

View File

@ -3,14 +3,13 @@
#include <dtl/dtl.hpp>
template <typename sesElem, typename stream = ostream >
class customChangePrinter : public dtl::Printer < sesElem, stream >
{
public :
customChangePrinter () : dtl::Printer < sesElem, stream > () {}
customChangePrinter (stream& out) : dtl::Printer < sesElem, stream > (out) {}
~customChangePrinter () {}
void operator() (const sesElem& se) const {
template <typename sesElem, typename stream = ostream>
class customChangePrinter : public dtl::Printer<sesElem, stream> {
public:
customChangePrinter() : dtl::Printer<sesElem, stream>() {}
customChangePrinter(stream &out) : dtl::Printer<sesElem, stream>(out) {}
~customChangePrinter() {}
void operator()(const sesElem &se) const {
switch (se.second.type) {
case dtl::SES_ADD:
this->out_ << "Add: " << se.first << std::endl;

View File

@ -1,16 +1,16 @@
#include <dtl/dtl.hpp>
#include "common.hpp"
#include <iostream>
#include <dtl/dtl.hpp>
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <vector>
using namespace std;
using namespace dtl;
int main(int argc, char *argv[]){
int main(int argc, char *argv[]) {
if (isFewArgs(argc, 2)) {
cerr << "Too few arguments." << endl;
@ -18,7 +18,7 @@ int main(int argc, char *argv[]){
}
typedef string elem;
typedef vector< string > sequence;
typedef vector<string> sequence;
string s(argv[1]);
@ -28,8 +28,9 @@ int main(int argc, char *argv[]){
}
ifstream fs(s.c_str());
const Ses< elem > ses = Diff< elem, sequence >::composeSesFromStream< ifstream >(fs);
dtl::Diff< elem, sequence >::printSES(ses);
const Ses<elem> ses =
Diff<elem, sequence>::composeSesFromStream<ifstream>(fs);
dtl::Diff<elem, sequence>::printSES(ses);
return 0;
}

View File

@ -3,13 +3,12 @@
#include <dtl/dtl.hpp>
template <typename sesElem, typename storedData >
class CustomStorage : public dtl::Storage < sesElem, storedData >
{
public :
CustomStorage(storedData& sd) : dtl::Storage < sesElem, storedData > (sd) {}
template <typename sesElem, typename storedData>
class CustomStorage : public dtl::Storage<sesElem, storedData> {
public:
CustomStorage(storedData &sd) : dtl::Storage<sesElem, storedData>(sd) {}
~CustomStorage() {}
void operator() (const sesElem& se) const {
void operator()(const sesElem &se) const {
switch (se.second.type) {
case dtl::SES_ADD:
this->storedData_ = this->storedData_ + "Add: " + se.first + "\n";

View File

@ -1,15 +1,15 @@
#include <dtl/dtl.hpp>
#include "common.hpp"
#include <dtl/dtl.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <vector>
using namespace std;
using dtl::Diff;
int main(int argc, char *argv[]){
int main(int argc, char *argv[]) {
if (isFewArgs(argc)) {
cerr << "Too few arguments." << endl;
@ -22,15 +22,15 @@ int main(int argc, char *argv[]){
sequence A(argv[1]);
sequence B(argv[2]);
Diff< elem, sequence > d(A, B);
//d.onOnlyEditDistance();
Diff<elem, sequence> d(A, B);
// d.onOnlyEditDistance();
d.compose();
// editDistance
cout << "editDistance:" << d.getEditDistance() << endl;
// Longest Common Subsequence
vector< elem > lcs_v = d.getLcsVec();
vector<elem> lcs_v = d.getLcsVec();
sequence lcs_s(lcs_v.begin(), lcs_v.end());
cout << "LCS:" << lcs_s << endl;

View File

@ -1,15 +1,15 @@
#include <dtl/dtl.hpp>
#include "common.hpp"
#include <dtl/dtl.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <vector>
using namespace std;
using dtl::Diff3;
int main(int argc, char *argv[]){
int main(int argc, char *argv[]) {
if (isFewArgs(argc, 4)) {
cerr << "Too few arguments." << endl;
@ -23,7 +23,7 @@ int main(int argc, char *argv[]){
sequence B(argv[2]);
sequence C(argv[3]);
Diff3< elem, sequence > diff3(A, B, C);
Diff3<elem, sequence> diff3(A, B, C);
diff3.compose();
if (!diff3.merge()) {
cerr << "conflict." << endl;

View File

@ -1,5 +1,5 @@
#include <dtl/dtl.hpp>
#include "common.hpp"
#include <dtl/dtl.hpp>
#include <iostream>
#include <sstream>
#include <string>
@ -10,7 +10,7 @@ using namespace std;
using dtl::Diff;
int main(int argc, char *argv[]){
int main(int argc, char *argv[]) {
if (isFewArgs(argc)) {
cerr << "Too few arguments." << endl;
@ -23,13 +23,13 @@ int main(int argc, char *argv[]){
sequence A(argv[1]);
sequence B(argv[2]);
Diff< elem, sequence > d(A, B);
Diff<elem, sequence> d(A, B);
d.compose();
// Shortest Edit Script
cout << "SES" << endl;
d.printSES < ostream, customChangePrinter > (cout);
d.printSES<ostream, customChangePrinter>(cout);
return 0;
}

View File

@ -1,5 +1,5 @@
#include <dtl/dtl.hpp>
#include "common.hpp"
#include <dtl/dtl.hpp>
#include <iostream>
#include <string>
@ -9,7 +9,7 @@ using namespace std;
using dtl::Diff;
int main(int argc, char *argv[]){
int main(int argc, char *argv[]) {
if (isFewArgs(argc)) {
cerr << "Too few arguments." << endl;
@ -22,7 +22,7 @@ int main(int argc, char *argv[]){
sequence A(argv[1]);
sequence B(argv[2]);
Diff< elem, sequence > d(A, B);
Diff<elem, sequence> d(A, B);
d.compose();
// Shortest Edit Script
@ -30,7 +30,7 @@ int main(int argc, char *argv[]){
string result;
d.storeSES < string, CustomStorage > (result);
d.storeSES<string, CustomStorage>(result);
cout << result;

View File

@ -1,13 +1,13 @@
#include <dtl/dtl.hpp>
#include "common.hpp"
#include <iostream>
#include <dtl/dtl.hpp>
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
#include <time.h>
#include <sys/stat.h>
#include <time.h>
using namespace std;
@ -15,11 +15,10 @@ using dtl::Diff;
using dtl::elemInfo;
using dtl::uniHunk;
static void showStats (string fp1, string fp2);
static void unifiedDiff (string fp1, string fp2);
static void showStats(string fp1, string fp2);
static void unifiedDiff(string fp1, string fp2);
static void showStats (string fp1, string fp2)
{
static void showStats(string fp1, string fp2) {
const int MAX_LENGTH = 255;
char time_format[] = "%Y-%m-%d %H:%M:%S %z";
time_t rawtime[2];
@ -46,31 +45,30 @@ static void showStats (string fp1, string fp2)
cout << "+++ " << fp2 << '\t' << buf[1] << endl;
}
static void unifiedDiff (string fp1, string fp2)
{
static void unifiedDiff(string fp1, string fp2) {
typedef string elem;
typedef vector< elem > sequence;
typedef pair< elem, elemInfo > sesElem;
typedef vector<elem> sequence;
typedef pair<elem, elemInfo> sesElem;
ifstream Aifs(fp1.c_str());
ifstream Bifs(fp2.c_str());
elem buf;
sequence ALines, BLines;
while(getline(Aifs, buf)){
while (getline(Aifs, buf)) {
ALines.push_back(buf);
}
while(getline(Bifs, buf)){
while (getline(Bifs, buf)) {
BLines.push_back(buf);
}
Diff< elem > diff(ALines, BLines);
Diff<elem> diff(ALines, BLines);
diff.onHuge();
//diff.onUnserious();
// diff.onUnserious();
diff.compose();
// type unihunk definition test
uniHunk< sesElem > hunk;
uniHunk<sesElem> hunk;
if (diff.getEditDistance() > 0) {
showStats(fp1, fp2); // show file info
@ -80,9 +78,7 @@ static void unifiedDiff (string fp1, string fp2)
diff.printUnifiedFormat();
}
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
if (isFewArgs(argc)) {
cerr << "Too few arguments." << endl;
return -1;

View File

@ -1,6 +1,6 @@
#include <dtl/dtl.hpp>
#include "common.hpp"
#include <dtl/dtl.hpp>
#include <iostream>
#include <vector>
@ -8,7 +8,7 @@ using namespace std;
using dtl::Diff;
int main(int argc, char *argv[]){
int main(int argc, char *argv[]) {
if (isFewArgs(argc)) {
cerr << "Too few arguments." << endl;
@ -21,7 +21,7 @@ int main(int argc, char *argv[]){
sequence A(argv[1]);
sequence B(argv[2]);
Diff<elem, sequence > d(A, B);
Diff<elem, sequence> d(A, B);
d.compose();
d.composeUnifiedHunks();

View File

@ -1,10 +1,8 @@
#include "dtl_test_common.hpp"
class Intdifftest : public ::testing::Test
{
protected :
dtl_test_typedefs(int, vector< int >)
typedef struct case_t {
class Intdifftest : public ::testing::Test {
protected:
dtl_test_typedefs(int, vector<int>) typedef struct case_t {
sequence A;
sequence B;
size_t editdis;
@ -17,13 +15,13 @@ protected :
string path_rses;
string path_rhunks;
} case_t;
typedef vector< case_t > caseVec;
typedef vector<case_t> caseVec;
caseVec cases;
case_t createCase (const sequence a, const sequence b, string test_name) {
case_t createCase(const sequence a, const sequence b, string test_name) {
case_t c;
string diff_name("intdiff");
Diff< elem > diff(a, b);
Diff<elem> diff(a, b);
diff.compose();
diff.composeUnifiedHunks();
@ -31,17 +29,19 @@ protected :
string path_lses = create_path(test_name, diff_name, TYPE_DIFF_SES);
string path_rses = create_path(test_name, diff_name, TYPE_DIFF_SES, true);
string path_lhunks = create_path(test_name, diff_name, TYPE_DIFF_UNI);
string path_rhunks = create_path(test_name, diff_name, TYPE_DIFF_UNI, true);
string path_rhunks =
create_path(test_name, diff_name, TYPE_DIFF_UNI, true);
create_file< elem, sequence, Compare< elem > >(path_rses, diff, TYPE_DIFF_SES);
create_file< elem, sequence, Compare< elem > >(path_rhunks, diff, TYPE_DIFF_UNI);
create_file<elem, sequence, Compare<elem>>(path_rses, diff,
TYPE_DIFF_SES);
create_file<elem, sequence, Compare<elem>>(path_rhunks, diff,
TYPE_DIFF_UNI);
c.editdis_ses = cal_diff_uni(path_lses, path_rses);
c.editdis_uni = cal_diff_uni(path_lhunks, path_rhunks);
c.path_rses = path_rses;
c.path_rhunks = path_rhunks;
}
c.A = a;
c.B = b;
c.editdis = diff.getEditDistance();
@ -74,10 +74,7 @@ protected :
cases.push_back(createCase(A5, B5, "diff_test4"));
}
void TearDown () {
for_each(cases.begin(), cases.end(), Remover< case_t >());
}
void TearDown() { for_each(cases.begin(), cases.end(), Remover<case_t>()); }
};
/**
@ -87,7 +84,7 @@ protected :
* - LCS
* - SES
*/
TEST_F (Intdifftest, diff_test0) {
TEST_F(Intdifftest, diff_test0) {
EXPECT_EQ(0, cases[0].editdis);
EXPECT_TRUE(cases[0].lcs_v.empty());
@ -97,7 +94,7 @@ TEST_F (Intdifftest, diff_test0) {
ASSERT_EQ(0, cases[0].editdis_uni);
}
TEST_F (Intdifftest, diff_test1) {
TEST_F(Intdifftest, diff_test1) {
EXPECT_EQ(1, cases[1].editdis);
EXPECT_TRUE(cases[1].lcs_v.empty());
@ -107,7 +104,7 @@ TEST_F (Intdifftest, diff_test1) {
ASSERT_EQ(0, cases[1].editdis_uni);
}
TEST_F (Intdifftest, diff_test2) {
TEST_F(Intdifftest, diff_test2) {
EXPECT_EQ(1, cases[2].editdis);
EXPECT_TRUE(cases[2].lcs_v.empty());
@ -117,7 +114,7 @@ TEST_F (Intdifftest, diff_test2) {
ASSERT_EQ(0, cases[2].editdis_uni);
}
TEST_F (Intdifftest, diff_test3) {
TEST_F(Intdifftest, diff_test3) {
EXPECT_EQ(8, cases[3].editdis);
EXPECT_EQ(3, cases[3].lcs_v[0]);
@ -131,7 +128,7 @@ TEST_F (Intdifftest, diff_test3) {
ASSERT_EQ(0, cases[3].editdis_uni);
}
TEST_F (Intdifftest, diff_test4) {
TEST_F(Intdifftest, diff_test4) {
EXPECT_EQ(4, cases[4].editdis);
EXPECT_EQ(3, cases[4].lcs_v[0]);

View File

@ -1,27 +1,26 @@
#include "dtl_test_common.hpp"
#include "comparators.hpp"
#include "dtl_test_common.hpp"
class Objdifftest : public ::testing::Test
{
protected :
dtl_test_typedefs(string, vector<elem>)
typedef struct case_t {
class Objdifftest : public ::testing::Test {
protected:
dtl_test_typedefs(string, vector<elem>) typedef struct case_t {
sequence A;
sequence B;
sesElemVec expected;
sesElemVec ses_seq;
} case_t;
typedef vector< case_t > caseVec;
typedef vector<case_t> caseVec;
caseVec obj_diff_cases;
template < typename comparator >
case_t createCase (const sequence a, const sequence b, sesElemVec ses, string test_name) {
template <typename comparator>
case_t createCase(const sequence a, const sequence b, sesElemVec ses,
string test_name) {
case_t c;
elemVec lcs_v;
string diff_name("objdiff");
Diff< elem, sequence, comparator > diff(a, b, true);
Diff<elem, sequence, comparator> diff(a, b, true);
diff.compose();
@ -41,13 +40,14 @@ protected :
sequence A(array1, array1 + (sizeof(array1) / sizeof(array1[0])));
sequence B(array2, array2 + (sizeof(array2) / sizeof(array2[0])));
dtl::Ses< elem > ses;
dtl::Ses<elem> ses;
ses.addSequence("the", 1, 1, dtl::SES_COMMON);
ses.addSequence("quick", 2, 2, dtl::SES_COMMON);
ses.addSequence("brown", 3, 0, dtl::SES_DELETE);
ses.addSequence("Fox", 0, 3, dtl::SES_ADD);
obj_diff_cases.push_back(createCase< StringCaseInsensitive >(A, B, ses.getSequence(), "objdiff_test0_pattern"));
obj_diff_cases.push_back(createCase<StringCaseInsensitive>(
A, B, ses.getSequence(), "objdiff_test0_pattern"));
}
{
@ -57,7 +57,7 @@ protected :
sequence A(array1, array1 + (sizeof(array1) / sizeof(array1[0])));
sequence B(array2, array2 + (sizeof(array2) / sizeof(array2[0])));
dtl::Ses< elem > ses;
dtl::Ses<elem> ses;
ses.addSequence("b", 1, 0, dtl::SES_DELETE);
ses.addSequence("c", 2, 0, dtl::SES_DELETE);
ses.addSequence("a", 0, 1, dtl::SES_ADD);
@ -67,7 +67,8 @@ protected :
ses.addSequence("f", 0, 4, dtl::SES_ADD);
ses.addSequence("h", 0, 5, dtl::SES_ADD);
obj_diff_cases.push_back(createCase< StringCaseInsensitive >(A, B, ses.getSequence(), "objdiff_test1_unswapped"));
obj_diff_cases.push_back(createCase<StringCaseInsensitive>(
A, B, ses.getSequence(), "objdiff_test1_unswapped"));
}
{
string array1[] = {"a", "d", "e", "f", "h"};
@ -76,7 +77,7 @@ protected :
sequence A(array1, array1 + (sizeof(array1) / sizeof(array1[0])));
sequence B(array2, array2 + (sizeof(array2) / sizeof(array2[0])));
dtl::Ses< elem > ses;
dtl::Ses<elem> ses;
ses.addSequence("a", 1, 0, dtl::SES_DELETE);
ses.addSequence("d", 2, 0, dtl::SES_DELETE);
ses.addSequence("b", 0, 1, dtl::SES_ADD);
@ -86,16 +87,17 @@ protected :
ses.addSequence("h", 5, 0, dtl::SES_DELETE);
ses.addSequence("g", 0, 4, dtl::SES_ADD);
obj_diff_cases.push_back(createCase< StringCaseInsensitive >(A, B, ses.getSequence(), "objdiff_test2_swapped"));
obj_diff_cases.push_back(createCase<StringCaseInsensitive>(
A, B, ses.getSequence(), "objdiff_test2_swapped"));
}
}
void TearDown () {
//for_each(obj_diff_cases.begin(), obj_diff_cases.end(), Remover< case_t >());
void TearDown() {
// for_each(obj_diff_cases.begin(), obj_diff_cases.end(), Remover< case_t
// >());
}
};
/**
* Objdifftest
* check list:
@ -103,14 +105,14 @@ protected :
* - Indepence of results from swapping
*/
TEST_F (Objdifftest, objdiff_test0_pattern) {
TEST_F(Objdifftest, objdiff_test0_pattern) {
EXPECT_EQ(obj_diff_cases[0].expected, obj_diff_cases[0].ses_seq);
}
TEST_F (Objdifftest, objdiff_test1_unswapped) {
TEST_F(Objdifftest, objdiff_test1_unswapped) {
EXPECT_EQ(obj_diff_cases[1].expected, obj_diff_cases[1].ses_seq);
}
TEST_F (Objdifftest, objdiff_test2_swapped) {
TEST_F(Objdifftest, objdiff_test2_swapped) {
EXPECT_EQ(obj_diff_cases[2].expected, obj_diff_cases[2].ses_seq);
}

View File

@ -1,23 +1,21 @@
#include "dtl_test_common.hpp"
class Patchtest : public ::testing::Test
{
protected :
dtl_test_typedefs(char, string)
typedef struct case_t {
class Patchtest : public ::testing::Test {
protected:
dtl_test_typedefs(char, string) typedef struct case_t {
sequence A;
sequence B;
Diff< elem, sequence > diff;
Diff<elem, sequence> diff;
} case_t;
typedef vector< case_t > caseVec;
typedef vector<case_t> caseVec;
caseVec cases;
case_t createCase (sequence a, sequence b) {
case_t createCase(sequence a, sequence b) {
case_t c;
c.A = a;
c.B = b;
c.diff = Diff< elem, sequence >(a, b);
c.diff = Diff<elem, sequence>(a, b);
c.diff.compose();
c.diff.composeUnifiedHunks();
return c;
@ -32,14 +30,69 @@ protected :
cases.push_back(createCase("", "")); // 5
cases.push_back(createCase("a", "")); // 6
cases.push_back(createCase("", "b")); // 7
cases.push_back(createCase("abcdefq3wefarhgorequgho4euhfteowauhfwehogfewrquhoi23hroewhoahfotrhguoiewahrgqqabcdef",
cases.push_back(createCase(
"abcdefq3wefarhgorequgho4euhfteowauhfwehogfewrquhoi23hroewhoahfotrhguoi"
"ewahrgqqabcdef",
"3abcdef4976fd86ouofita67t85r876e5e746578tgliuhopoqqabcdef")); // 8
cases.push_back(createCase("abcqqqeqqqccc", "abdqqqeqqqddd")); // 9
cases.push_back(createCase("aaaaaaaaaaaaa>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>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
/**
@ -48,57 +101,57 @@ protected :
* - patch function
* - uniPatch function
*/
TEST_F (Patchtest, patch_test0) {
TEST_F(Patchtest, patch_test0) {
ASSERT_EQ(cases[0].B, cases[0].diff.patch(cases[0].A));
ASSERT_EQ(cases[0].B, cases[0].diff.uniPatch(cases[0].A));
}
TEST_F (Patchtest, patch_test1) {
TEST_F(Patchtest, patch_test1) {
ASSERT_EQ(cases[1].B, cases[1].diff.patch(cases[1].A));
ASSERT_EQ(cases[1].B, cases[1].diff.uniPatch(cases[1].A));
}
TEST_F (Patchtest, patch_test2) {
TEST_F(Patchtest, patch_test2) {
ASSERT_EQ(cases[2].B, cases[2].diff.patch(cases[2].A));
ASSERT_EQ(cases[2].B, cases[2].diff.uniPatch(cases[2].A));
}
TEST_F (Patchtest, patch_test3) {
TEST_F(Patchtest, patch_test3) {
ASSERT_EQ(cases[3].B, cases[3].diff.patch(cases[3].A));
ASSERT_EQ(cases[3].B, cases[3].diff.uniPatch(cases[3].A));
}
TEST_F (Patchtest, patch_test4) {
TEST_F(Patchtest, patch_test4) {
ASSERT_EQ(cases[4].B, cases[4].diff.patch(cases[4].A));
ASSERT_EQ(cases[4].B, cases[4].diff.uniPatch(cases[4].A));
}
TEST_F (Patchtest, patch_test5) {
TEST_F(Patchtest, patch_test5) {
ASSERT_EQ(cases[5].B, cases[5].diff.patch(cases[5].A));
ASSERT_EQ(cases[5].B, cases[5].diff.uniPatch(cases[5].A));
}
TEST_F (Patchtest, patch_test6) {
TEST_F(Patchtest, patch_test6) {
ASSERT_EQ(cases[6].B, cases[6].diff.patch(cases[6].A));
ASSERT_EQ(cases[6].B, cases[6].diff.uniPatch(cases[6].A));
}
TEST_F (Patchtest, patch_test7) {
TEST_F(Patchtest, patch_test7) {
ASSERT_EQ(cases[7].B, cases[7].diff.patch(cases[7].A));
ASSERT_EQ(cases[7].B, cases[7].diff.uniPatch(cases[7].A));
}
TEST_F (Patchtest, patch_test8) {
TEST_F(Patchtest, patch_test8) {
ASSERT_EQ(cases[8].B, cases[8].diff.patch(cases[8].A));
ASSERT_EQ(cases[8].B, cases[8].diff.uniPatch(cases[8].A));
}
TEST_F (Patchtest, patch_test9) {
TEST_F(Patchtest, patch_test9) {
ASSERT_EQ(cases[9].B, cases[9].diff.patch(cases[9].A));
ASSERT_EQ(cases[9].B, cases[9].diff.uniPatch(cases[9].A));
}
TEST_F (Patchtest, patch_test10) {
TEST_F(Patchtest, patch_test10) {
ASSERT_EQ(cases[10].B, cases[10].diff.patch(cases[10].A));
ASSERT_EQ(cases[10].B, cases[10].diff.uniPatch(cases[10].A));
}

View File

@ -3,18 +3,20 @@
import os
def path_chomp(path):
if path[-1] == '/':
return path[:-1]
return path
env = Environment(
CPPFLAGS=['-Wall', '-O2'],
CPPPATH=['..'],
CXXFLAGS="-std=c++11",
)
conf = Configure(env);
conf = Configure(env)
if not conf.CheckCXX():
print("c++ compiler is not installed!")
@ -33,10 +35,6 @@ test = env.Program(
[Glob('*.cpp')],
)
test_alias = env.Alias(
'check',
test,
test[0].abspath
)
test_alias = env.Alias('check', test, test[0].abspath)
env.AlwaysBuild(test_alias)

View File

@ -1,24 +1,22 @@
#include "dtl_test_common.hpp"
#include "comparators.hpp"
#include "dtl_test_common.hpp"
class Strdiff3test : public ::testing::Test
{
protected :
dtl_test_typedefs(char, string)
typedef struct case_t {
class Strdiff3test : public ::testing::Test {
protected:
dtl_test_typedefs(char, string) typedef struct case_t {
sequence S;
bool is_merge_success;
sequence merged_seq;
} case_t;
typedef vector< case_t > caseVec;
typedef vector<case_t> caseVec;
caseVec merge_cases;
caseVec detect_cases;
caseVec custom_cases;
template < typename comparator >
case_t createCase (sequence a, sequence b, sequence c, sequence s) {
Diff3< elem, sequence, comparator > diff3(a, b, c);
template <typename comparator>
case_t createCase(sequence a, sequence b, sequence c, sequence s) {
Diff3<elem, sequence, comparator> diff3(a, b, c);
case_t ct;
diff3.compose();
@ -31,41 +29,67 @@ protected :
void SetUp() {
// merge test
merge_cases.push_back(createCase< Compare < elem > >("ab", "b", "bc", "abc")); // 0
merge_cases.push_back(createCase< Compare < elem > >("bc", "b", "ab", "abc")); // 1
merge_cases.push_back(createCase< Compare < elem > >("qqqabc", "abc", "abcdef", "qqqabcdef")); // 2
merge_cases.push_back(createCase< Compare < elem > >("abcdef", "abc", "qqqabc", "qqqabcdef")); // 3
merge_cases.push_back(createCase< Compare < elem > >("aaacccbbb", "aaabbb", "aaabbbqqq", "aaacccbbbqqq")); // 4
merge_cases.push_back(createCase< Compare < elem > >("aaabbbqqq", "aaabbb", "aaacccbbb", "aaacccbbbqqq")); // 5
merge_cases.push_back(createCase< Compare < elem > >("aeaacccbbb", "aaabbb", "aaabbbqqq", "aeaacccbbbqqq")); // 6
merge_cases.push_back(createCase< Compare < elem > >("aaabbbqqq", "aaabbb", "aeaacccbbb", "aeaacccbbbqqq")); // 7
merge_cases.push_back(createCase< Compare < elem > >("aeaacccbbb", "aaabbb", "aaabebbqqq", "aeaacccbebbqqq")); // 8
merge_cases.push_back(createCase< Compare < elem > >("aaabebbqqq", "aaabbb", "aeaacccbbb", "aeaacccbebbqqq")); // 9
merge_cases.push_back(createCase< Compare < elem > >("aaacccbbb", "aaabbb", "aeaabbbqqq", "aeaacccbbbqqq")); // 10
merge_cases.push_back(createCase< Compare < elem > >("aeaabbbqqq", "aaabbb", "aaacccbbb", "aeaacccbbbqqq")); // 11
merge_cases.push_back(createCase< Compare < elem > >("aaacccbbb", "aaabbb", "aaabeebbeeqqq","aaacccbeebbeeqqq")); // 12
merge_cases.push_back(createCase< Compare < elem > >("aaabeebbeeqqq", "aaabbb", "aaacccbbb", "aaacccbeebbeeqqq")); // 13
merge_cases.push_back(createCase< Compare < elem > >("aiueo", "aeo", "aeKokaki", "aiueKokaki")); // 14
merge_cases.push_back(createCase< Compare < elem > >("aeKokaki", "aeo", "aiueo", "aiueKokaki")); // 15
merge_cases.push_back(createCase< Compare < elem > >("1234567390", "1234567890", "1239567890", "1239567390")); // 16
merge_cases.push_back(createCase< Compare < elem > >("1239567890", "1234567890", "1234567390", "1239567390")); // 17
merge_cases.push_back(createCase< Compare < elem > >("qabcdef", "abcdef", "ab", "qab")); // 18
merge_cases.push_back(createCase< Compare < elem > >("ab", "abcdef", "qabcdef", "qab")); // 19
merge_cases.push_back(createCase< Compare < elem > >("abcdf", "abcdef", "acdef", "acdf")); // 20
merge_cases.push_back(createCase< Compare < elem > >("acdef", "abcdef", "abcdf", "acdf")); // 21
merge_cases.push_back(createCase< Compare < elem > >("acdef", "abcdef", "abcdfaa", "acdfaa")); // 22
merge_cases.push_back(createCase< Compare < elem > >("abcdfaa", "abcdef", "acdef", "acdfaa")); // 23
merge_cases.push_back(
createCase<Compare<elem>>("ab", "b", "bc", "abc")); // 0
merge_cases.push_back(
createCase<Compare<elem>>("bc", "b", "ab", "abc")); // 1
merge_cases.push_back(
createCase<Compare<elem>>("qqqabc", "abc", "abcdef", "qqqabcdef")); // 2
merge_cases.push_back(
createCase<Compare<elem>>("abcdef", "abc", "qqqabc", "qqqabcdef")); // 3
merge_cases.push_back(createCase<Compare<elem>>(
"aaacccbbb", "aaabbb", "aaabbbqqq", "aaacccbbbqqq")); // 4
merge_cases.push_back(createCase<Compare<elem>>(
"aaabbbqqq", "aaabbb", "aaacccbbb", "aaacccbbbqqq")); // 5
merge_cases.push_back(createCase<Compare<elem>>(
"aeaacccbbb", "aaabbb", "aaabbbqqq", "aeaacccbbbqqq")); // 6
merge_cases.push_back(createCase<Compare<elem>>(
"aaabbbqqq", "aaabbb", "aeaacccbbb", "aeaacccbbbqqq")); // 7
merge_cases.push_back(createCase<Compare<elem>>(
"aeaacccbbb", "aaabbb", "aaabebbqqq", "aeaacccbebbqqq")); // 8
merge_cases.push_back(createCase<Compare<elem>>(
"aaabebbqqq", "aaabbb", "aeaacccbbb", "aeaacccbebbqqq")); // 9
merge_cases.push_back(createCase<Compare<elem>>(
"aaacccbbb", "aaabbb", "aeaabbbqqq", "aeaacccbbbqqq")); // 10
merge_cases.push_back(createCase<Compare<elem>>(
"aeaabbbqqq", "aaabbb", "aaacccbbb", "aeaacccbbbqqq")); // 11
merge_cases.push_back(createCase<Compare<elem>>(
"aaacccbbb", "aaabbb", "aaabeebbeeqqq", "aaacccbeebbeeqqq")); // 12
merge_cases.push_back(createCase<Compare<elem>>(
"aaabeebbeeqqq", "aaabbb", "aaacccbbb", "aaacccbeebbeeqqq")); // 13
merge_cases.push_back(createCase<Compare<elem>>("aiueo", "aeo", "aeKokaki",
"aiueKokaki")); // 14
merge_cases.push_back(createCase<Compare<elem>>("aeKokaki", "aeo", "aiueo",
"aiueKokaki")); // 15
merge_cases.push_back(createCase<Compare<elem>>(
"1234567390", "1234567890", "1239567890", "1239567390")); // 16
merge_cases.push_back(createCase<Compare<elem>>(
"1239567890", "1234567890", "1234567390", "1239567390")); // 17
merge_cases.push_back(
createCase<Compare<elem>>("qabcdef", "abcdef", "ab", "qab")); // 18
merge_cases.push_back(
createCase<Compare<elem>>("ab", "abcdef", "qabcdef", "qab")); // 19
merge_cases.push_back(
createCase<Compare<elem>>("abcdf", "abcdef", "acdef", "acdf")); // 20
merge_cases.push_back(
createCase<Compare<elem>>("acdef", "abcdef", "abcdf", "acdf")); // 21
merge_cases.push_back(createCase<Compare<elem>>("acdef", "abcdef",
"abcdfaa", "acdfaa")); // 22
merge_cases.push_back(createCase<Compare<elem>>("abcdfaa", "abcdef",
"acdef", "acdfaa")); // 23
// detect confliction test
detect_cases.push_back(createCase< Compare < elem > >("adc", "abc", "aec", "")); // 0
detect_cases.push_back(createCase< Compare < elem > >("abqdcf", "abcdef", "abqqef", "")); // 1
detect_cases.push_back(
createCase<Compare<elem>>("adc", "abc", "aec", "")); // 0
detect_cases.push_back(
createCase<Compare<elem>>("abqdcf", "abcdef", "abqqef", "")); // 1
// use custom comparator
custom_cases.push_back(createCase< CaseInsensitive >("abc", "abc", "abC", "abc"));
custom_cases.push_back(
createCase<CaseInsensitive>("abc", "abc", "abC", "abc"));
}
void TearDown () {}
void TearDown() {}
};
/**
@ -74,135 +98,135 @@ protected :
* - merge function
* - detect confliction
*/
TEST_F (Strdiff3test, merge_test0) {
TEST_F(Strdiff3test, merge_test0) {
ASSERT_TRUE(merge_cases[0].is_merge_success);
ASSERT_EQ(merge_cases[0].S, merge_cases[0].merged_seq);
}
TEST_F (Strdiff3test, merge_test1) {
TEST_F(Strdiff3test, merge_test1) {
ASSERT_TRUE(merge_cases[1].is_merge_success);
ASSERT_EQ(merge_cases[1].S, merge_cases[1].merged_seq);
}
TEST_F (Strdiff3test, merge_test2) {
TEST_F(Strdiff3test, merge_test2) {
ASSERT_TRUE(merge_cases[2].is_merge_success);
ASSERT_EQ(merge_cases[2].S, merge_cases[2].merged_seq);
}
TEST_F (Strdiff3test, merge_test3) {
TEST_F(Strdiff3test, merge_test3) {
ASSERT_TRUE(merge_cases[3].is_merge_success);
ASSERT_EQ(merge_cases[3].S, merge_cases[3].merged_seq);
}
TEST_F (Strdiff3test, merge_test4) {
TEST_F(Strdiff3test, merge_test4) {
ASSERT_TRUE(merge_cases[4].is_merge_success);
ASSERT_EQ(merge_cases[4].S, merge_cases[4].merged_seq);
}
TEST_F (Strdiff3test, merge_test5) {
TEST_F(Strdiff3test, merge_test5) {
ASSERT_TRUE(merge_cases[5].is_merge_success);
ASSERT_EQ(merge_cases[5].S, merge_cases[5].merged_seq);
}
TEST_F (Strdiff3test, merge_test6) {
TEST_F(Strdiff3test, merge_test6) {
ASSERT_TRUE(merge_cases[6].is_merge_success);
ASSERT_EQ(merge_cases[6].S, merge_cases[6].merged_seq);
}
TEST_F (Strdiff3test, merge_test7) {
TEST_F(Strdiff3test, merge_test7) {
ASSERT_TRUE(merge_cases[7].is_merge_success);
ASSERT_EQ(merge_cases[7].S, merge_cases[7].merged_seq);
}
TEST_F (Strdiff3test, merge_test8) {
TEST_F(Strdiff3test, merge_test8) {
ASSERT_TRUE(merge_cases[8].is_merge_success);
ASSERT_EQ(merge_cases[8].S, merge_cases[8].merged_seq);
}
TEST_F (Strdiff3test, merge_test9) {
TEST_F(Strdiff3test, merge_test9) {
ASSERT_TRUE(merge_cases[9].is_merge_success);
ASSERT_EQ(merge_cases[9].S, merge_cases[9].merged_seq);
}
TEST_F (Strdiff3test, merge_test10) {
TEST_F(Strdiff3test, merge_test10) {
ASSERT_TRUE(merge_cases[10].is_merge_success);
ASSERT_EQ(merge_cases[10].S, merge_cases[10].merged_seq);
}
TEST_F (Strdiff3test, merge_test11) {
TEST_F(Strdiff3test, merge_test11) {
ASSERT_TRUE(merge_cases[11].is_merge_success);
ASSERT_EQ(merge_cases[11].S, merge_cases[11].merged_seq);
}
TEST_F (Strdiff3test, merge_test12) {
TEST_F(Strdiff3test, merge_test12) {
ASSERT_TRUE(merge_cases[12].is_merge_success);
ASSERT_EQ(merge_cases[12].S, merge_cases[12].merged_seq);
}
TEST_F (Strdiff3test, merge_test13) {
TEST_F(Strdiff3test, merge_test13) {
ASSERT_TRUE(merge_cases[13].is_merge_success);
ASSERT_EQ(merge_cases[13].S, merge_cases[13].merged_seq);
}
TEST_F (Strdiff3test, merge_test14) {
TEST_F(Strdiff3test, merge_test14) {
ASSERT_TRUE(merge_cases[14].is_merge_success);
ASSERT_EQ(merge_cases[14].S, merge_cases[14].merged_seq);
}
TEST_F (Strdiff3test, merge_test15) {
TEST_F(Strdiff3test, merge_test15) {
ASSERT_TRUE(merge_cases[15].is_merge_success);
ASSERT_EQ(merge_cases[15].S, merge_cases[15].merged_seq);
}
TEST_F (Strdiff3test, merge_test16) {
TEST_F(Strdiff3test, merge_test16) {
ASSERT_TRUE(merge_cases[16].is_merge_success);
ASSERT_EQ(merge_cases[16].S, merge_cases[16].merged_seq);
}
TEST_F (Strdiff3test, merge_test17) {
TEST_F(Strdiff3test, merge_test17) {
ASSERT_TRUE(merge_cases[17].is_merge_success);
ASSERT_EQ(merge_cases[17].S, merge_cases[17].merged_seq);
}
TEST_F (Strdiff3test, merge_test18) {
TEST_F(Strdiff3test, merge_test18) {
ASSERT_TRUE(merge_cases[18].is_merge_success);
ASSERT_EQ(merge_cases[18].S, merge_cases[18].merged_seq);
}
TEST_F (Strdiff3test, merge_test19) {
TEST_F(Strdiff3test, merge_test19) {
ASSERT_TRUE(merge_cases[19].is_merge_success);
ASSERT_EQ(merge_cases[19].S, merge_cases[19].merged_seq);
}
TEST_F (Strdiff3test, merge_test20) {
TEST_F(Strdiff3test, merge_test20) {
ASSERT_TRUE(merge_cases[20].is_merge_success);
ASSERT_EQ(merge_cases[20].S, merge_cases[20].merged_seq);
}
TEST_F (Strdiff3test, merge_test21) {
TEST_F(Strdiff3test, merge_test21) {
ASSERT_TRUE(merge_cases[21].is_merge_success);
ASSERT_EQ( merge_cases[21].S, merge_cases[21].merged_seq);
ASSERT_EQ(merge_cases[21].S, merge_cases[21].merged_seq);
}
TEST_F (Strdiff3test, merge_test22) {
TEST_F(Strdiff3test, merge_test22) {
ASSERT_TRUE(merge_cases[22].is_merge_success);
ASSERT_EQ( merge_cases[22].S, merge_cases[22].merged_seq);
ASSERT_EQ(merge_cases[22].S, merge_cases[22].merged_seq);
}
TEST_F (Strdiff3test, merge_test23) {
TEST_F(Strdiff3test, merge_test23) {
ASSERT_TRUE(merge_cases[23].is_merge_success);
ASSERT_EQ(merge_cases[23].S, merge_cases[23].merged_seq);
}
TEST_F (Strdiff3test, detect_confliction_test0) {
TEST_F(Strdiff3test, detect_confliction_test0) {
ASSERT_FALSE(detect_cases[0].is_merge_success);
}
TEST_F (Strdiff3test, detect_confliction_test1) {
TEST_F(Strdiff3test, detect_confliction_test1) {
ASSERT_FALSE(detect_cases[1].is_merge_success);
}
TEST_F (Strdiff3test, custom_comparator_test0) {
TEST_F(Strdiff3test, custom_comparator_test0) {
ASSERT_TRUE(custom_cases[0].is_merge_success);
ASSERT_EQ(custom_cases[0].S, custom_cases[0].merged_seq);
}

View File

@ -1,11 +1,9 @@
#include "dtl_test_common.hpp"
#include "comparators.hpp"
#include "dtl_test_common.hpp"
class Strdifftest : public ::testing::Test
{
protected :
dtl_test_typedefs(char, string)
typedef struct case_t {
class Strdifftest : public ::testing::Test {
protected:
dtl_test_typedefs(char, string) typedef struct case_t {
sequence A;
sequence B;
size_t editdis;
@ -18,19 +16,20 @@ protected :
string path_rses;
string path_rhunks;
} case_t;
typedef vector< case_t > caseVec;
typedef vector<case_t> caseVec;
caseVec diff_cases;
caseVec only_editdis_cases;
caseVec custom_cases;
template < typename comparator >
case_t createCase (const sequence a, const sequence b, string test_name, bool onlyEditdis = false) {
template <typename comparator>
case_t createCase(const sequence a, const sequence b, string test_name,
bool onlyEditdis = false) {
case_t c;
elemVec lcs_v;
string diff_name("strdiff");
Diff< elem, sequence, comparator > diff(a, b);
Diff<elem, sequence, comparator> diff(a, b);
if (onlyEditdis) {
diff.onOnlyEditDistance();
}
@ -43,12 +42,13 @@ protected :
string path_lses = create_path(test_name, diff_name, TYPE_DIFF_SES);
string path_rses = create_path(test_name, diff_name, TYPE_DIFF_SES, true);
string path_lhunks = create_path(test_name, diff_name, TYPE_DIFF_UNI);
string path_rhunks = create_path(test_name, diff_name, TYPE_DIFF_UNI, true);
string path_rhunks =
create_path(test_name, diff_name, TYPE_DIFF_UNI, true);
diff_resultset_exist_check(path_lses);
diff_resultset_exist_check(path_lhunks);
create_file< elem, sequence, comparator >(path_rses, diff, TYPE_DIFF_SES);
create_file< elem, sequence, comparator >(path_rhunks, diff, TYPE_DIFF_UNI);
create_file<elem, sequence, comparator>(path_rses, diff, TYPE_DIFF_SES);
create_file<elem, sequence, comparator>(path_rhunks, diff, TYPE_DIFF_UNI);
c.editdis_ses = cal_diff_uni(path_lses, path_rses);
c.editdis_uni = cal_diff_uni(path_lhunks, path_rhunks);
@ -67,36 +67,47 @@ protected :
}
void SetUp(void) {
diff_cases.push_back(createCase< Compare< elem > >("abc", "abd", "diff_test0"));
diff_cases.push_back(createCase< Compare< elem > >("acbdeacbed", "acebdabbabed", "diff_test1"));
diff_cases.push_back(createCase< Compare< elem > >("abcdef", "dacfea", "diff_test2"));
diff_cases.push_back(createCase< Compare< elem > >("abcbda", "bdcaba", "diff_test3"));
diff_cases.push_back(createCase< Compare< elem > >("bokko", "bokkko", "diff_test4"));
diff_cases.push_back(createCase< Compare< elem > >("", "", "diff_test5"));
diff_cases.push_back(createCase< Compare< elem > >("a", "", "diff_test6"));
diff_cases.push_back(createCase< Compare< elem > >("", "b", "diff_test7"));
diff_cases.push_back(createCase< Compare< elem > >("acbdeaqqqqqqqcbed", "acebdabbqqqqqqqabed", "diff_test8"));
diff_cases.push_back(createCase<Compare<elem>>("abc", "abd", "diff_test0"));
diff_cases.push_back(
createCase<Compare<elem>>("acbdeacbed", "acebdabbabed", "diff_test1"));
diff_cases.push_back(
createCase<Compare<elem>>("abcdef", "dacfea", "diff_test2"));
diff_cases.push_back(
createCase<Compare<elem>>("abcbda", "bdcaba", "diff_test3"));
diff_cases.push_back(
createCase<Compare<elem>>("bokko", "bokkko", "diff_test4"));
diff_cases.push_back(createCase<Compare<elem>>("", "", "diff_test5"));
diff_cases.push_back(createCase<Compare<elem>>("a", "", "diff_test6"));
diff_cases.push_back(createCase<Compare<elem>>("", "b", "diff_test7"));
diff_cases.push_back(createCase<Compare<elem>>(
"acbdeaqqqqqqqcbed", "acebdabbqqqqqqqabed", "diff_test8"));
only_editdis_cases.push_back(createCase< Compare< elem > >("abc", "abd", "", true));
only_editdis_cases.push_back(createCase< Compare< elem > >("acbdeacbed", "acebdabbabed", "", true));
only_editdis_cases.push_back(createCase< Compare< elem > >("abcdef", "dacfea", "", true));
only_editdis_cases.push_back(createCase< Compare< elem > >("abcbda", "bdcaba", "", true));
only_editdis_cases.push_back(createCase< Compare< elem > >("bokko", "bokkko", "", true));
only_editdis_cases.push_back(createCase< Compare< elem > >("", "", "", true));
only_editdis_cases.push_back(createCase< Compare< elem > >("a", "", "", true));
only_editdis_cases.push_back(createCase< Compare< elem > >("", "b", "", true));
only_editdis_cases.push_back(createCase< Compare< elem > >("acbdeaqqqqqqqcbed", "acebdabbqqqqqqqabed", "", true));
only_editdis_cases.push_back(
createCase<Compare<elem>>("abc", "abd", "", true));
only_editdis_cases.push_back(
createCase<Compare<elem>>("acbdeacbed", "acebdabbabed", "", true));
only_editdis_cases.push_back(
createCase<Compare<elem>>("abcdef", "dacfea", "", true));
only_editdis_cases.push_back(
createCase<Compare<elem>>("abcbda", "bdcaba", "", true));
only_editdis_cases.push_back(
createCase<Compare<elem>>("bokko", "bokkko", "", true));
only_editdis_cases.push_back(createCase<Compare<elem>>("", "", "", true));
only_editdis_cases.push_back(createCase<Compare<elem>>("a", "", "", true));
only_editdis_cases.push_back(createCase<Compare<elem>>("", "b", "", true));
only_editdis_cases.push_back(createCase<Compare<elem>>(
"acbdeaqqqqqqqcbed", "acebdabbqqqqqqqabed", "", true));
custom_cases.push_back(createCase< CaseInsensitive >("abc", "Abc", "custom_test0"));
custom_cases.push_back(
createCase<CaseInsensitive>("abc", "Abc", "custom_test0"));
}
void TearDown () {
for_each(diff_cases.begin(), diff_cases.end(), Remover< case_t >());
for_each(custom_cases.begin(), custom_cases.end(), Remover< case_t >());
void TearDown() {
for_each(diff_cases.begin(), diff_cases.end(), Remover<case_t>());
for_each(custom_cases.begin(), custom_cases.end(), Remover<case_t>());
}
};
/**
* Strdifftest
* check list is following
@ -107,7 +118,7 @@ protected :
* - onOnlyEditDistance
*/
TEST_F (Strdifftest, diff_test0) {
TEST_F(Strdifftest, diff_test0) {
EXPECT_EQ(2, diff_cases[0].editdis);
@ -118,7 +129,7 @@ TEST_F (Strdifftest, diff_test0) {
ASSERT_EQ(0, diff_cases[0].editdis_uni);
}
TEST_F (Strdifftest, diff_test1) {
TEST_F(Strdifftest, diff_test1) {
EXPECT_EQ(6, diff_cases[1].editdis);
EXPECT_EQ("acbdabed", diff_cases[1].lcs_s);
@ -128,7 +139,7 @@ TEST_F (Strdifftest, diff_test1) {
ASSERT_EQ(0, diff_cases[1].editdis_uni);
}
TEST_F (Strdifftest, diff_test2) {
TEST_F(Strdifftest, diff_test2) {
EXPECT_EQ(6, diff_cases[2].editdis);
EXPECT_EQ("acf", diff_cases[2].lcs_s);
@ -138,7 +149,7 @@ TEST_F (Strdifftest, diff_test2) {
ASSERT_EQ(0, diff_cases[2].editdis_uni);
}
TEST_F (Strdifftest, diff_test3) {
TEST_F(Strdifftest, diff_test3) {
EXPECT_EQ(4, diff_cases[3].editdis);
EXPECT_EQ("bcba", diff_cases[3].lcs_s);
@ -148,7 +159,7 @@ TEST_F (Strdifftest, diff_test3) {
ASSERT_EQ(0, diff_cases[3].editdis_uni);
}
TEST_F (Strdifftest, diff_test4) {
TEST_F(Strdifftest, diff_test4) {
EXPECT_EQ(1, diff_cases[4].editdis);
EXPECT_EQ("bokko", diff_cases[4].lcs_s);
@ -158,7 +169,7 @@ TEST_F (Strdifftest, diff_test4) {
ASSERT_EQ(0, diff_cases[4].editdis_uni);
}
TEST_F (Strdifftest, diff_test5) {
TEST_F(Strdifftest, diff_test5) {
EXPECT_EQ(0, diff_cases[5].editdis);
EXPECT_EQ("", diff_cases[5].lcs_s);
@ -168,7 +179,7 @@ TEST_F (Strdifftest, diff_test5) {
ASSERT_EQ(0, diff_cases[5].editdis_uni);
}
TEST_F (Strdifftest, diff_test6) {
TEST_F(Strdifftest, diff_test6) {
EXPECT_EQ(1, diff_cases[6].editdis);
EXPECT_EQ("", diff_cases[6].lcs_s);
@ -178,7 +189,7 @@ TEST_F (Strdifftest, diff_test6) {
ASSERT_EQ(0, diff_cases[6].editdis_uni);
}
TEST_F (Strdifftest, diff_test7) {
TEST_F(Strdifftest, diff_test7) {
EXPECT_EQ(1, diff_cases[7].editdis);
EXPECT_EQ("", diff_cases[7].lcs_s);
@ -188,7 +199,7 @@ TEST_F (Strdifftest, diff_test7) {
ASSERT_EQ(0, diff_cases[7].editdis_uni);
}
TEST_F (Strdifftest, diff_test8) {
TEST_F(Strdifftest, diff_test8) {
EXPECT_EQ(6, diff_cases[8].editdis);
EXPECT_EQ("acbdaqqqqqqqbed", diff_cases[8].lcs_s);
@ -198,7 +209,7 @@ TEST_F (Strdifftest, diff_test8) {
ASSERT_EQ(0, diff_cases[8].editdis_uni);
}
TEST_F (Strdifftest, only_editdis_test0) {
TEST_F(Strdifftest, only_editdis_test0) {
EXPECT_EQ(2, only_editdis_cases[0].editdis);
EXPECT_EQ("", only_editdis_cases[0].lcs_s);
@ -208,7 +219,7 @@ TEST_F (Strdifftest, only_editdis_test0) {
ASSERT_TRUE(only_editdis_cases[0].hunk_v.empty());
}
TEST_F (Strdifftest, only_editdis_test1) {
TEST_F(Strdifftest, only_editdis_test1) {
EXPECT_EQ(6, only_editdis_cases[1].editdis);
EXPECT_EQ("", only_editdis_cases[1].lcs_s);
@ -218,7 +229,7 @@ TEST_F (Strdifftest, only_editdis_test1) {
ASSERT_TRUE(only_editdis_cases[1].hunk_v.empty());
}
TEST_F (Strdifftest, only_editdis_test2) {
TEST_F(Strdifftest, only_editdis_test2) {
EXPECT_EQ(6, only_editdis_cases[2].editdis);
EXPECT_EQ("", only_editdis_cases[2].lcs_s);
@ -228,7 +239,7 @@ TEST_F (Strdifftest, only_editdis_test2) {
ASSERT_TRUE(only_editdis_cases[2].hunk_v.empty());
}
TEST_F (Strdifftest, only_editdis_test3) {
TEST_F(Strdifftest, only_editdis_test3) {
EXPECT_EQ(4, only_editdis_cases[3].editdis);
EXPECT_EQ("", only_editdis_cases[3].lcs_s);
@ -238,7 +249,7 @@ TEST_F (Strdifftest, only_editdis_test3) {
ASSERT_TRUE(only_editdis_cases[3].hunk_v.empty());
}
TEST_F (Strdifftest, only_editdis_test4) {
TEST_F(Strdifftest, only_editdis_test4) {
EXPECT_EQ(1, only_editdis_cases[4].editdis);
EXPECT_EQ("", only_editdis_cases[4].lcs_s);
@ -248,7 +259,7 @@ TEST_F (Strdifftest, only_editdis_test4) {
ASSERT_TRUE(only_editdis_cases[4].hunk_v.empty());
}
TEST_F (Strdifftest, only_editdis_test5) {
TEST_F(Strdifftest, only_editdis_test5) {
EXPECT_EQ(0, only_editdis_cases[5].editdis);
EXPECT_EQ("", only_editdis_cases[5].lcs_s);
@ -258,7 +269,7 @@ TEST_F (Strdifftest, only_editdis_test5) {
ASSERT_TRUE(only_editdis_cases[5].hunk_v.empty());
}
TEST_F (Strdifftest, only_editdis_test6) {
TEST_F(Strdifftest, only_editdis_test6) {
EXPECT_EQ(1, only_editdis_cases[6].editdis);
EXPECT_EQ("", only_editdis_cases[6].lcs_s);
@ -268,7 +279,7 @@ TEST_F (Strdifftest, only_editdis_test6) {
ASSERT_TRUE(only_editdis_cases[6].hunk_v.empty());
}
TEST_F (Strdifftest, only_editdis_test7) {
TEST_F(Strdifftest, only_editdis_test7) {
EXPECT_EQ(1, only_editdis_cases[7].editdis);
EXPECT_EQ("", only_editdis_cases[7].lcs_s);
@ -278,7 +289,7 @@ TEST_F (Strdifftest, only_editdis_test7) {
ASSERT_TRUE(only_editdis_cases[7].hunk_v.empty());
}
TEST_F (Strdifftest, only_editdis_test8) {
TEST_F(Strdifftest, only_editdis_test8) {
EXPECT_EQ(6, only_editdis_cases[8].editdis);
EXPECT_EQ("", only_editdis_cases[8].lcs_s);
@ -288,7 +299,7 @@ TEST_F (Strdifftest, only_editdis_test8) {
ASSERT_TRUE(only_editdis_cases[8].hunk_v.empty());
}
TEST_F (Strdifftest, custom_comparator_test0) {
TEST_F(Strdifftest, custom_comparator_test0) {
EXPECT_EQ(0, custom_cases[0].editdis);
EXPECT_EQ("abc", custom_cases[0].lcs_s);

View File

@ -1,21 +1,20 @@
#ifndef DTL_COMPARATORS
#define DTL_COMPARATORS
class CaseInsensitive: public dtl::Compare<char> {
class CaseInsensitive : public dtl::Compare<char> {
public:
virtual bool impl(const char& a, const char& b) const {
virtual bool impl(const char &a, const char &b) const {
return tolower(a) == tolower(b);
}
};
class StringCaseInsensitive: public dtl::Compare<string> {
class StringCaseInsensitive : public dtl::Compare<string> {
public:
virtual bool impl(const string& a, const string& b) const {
virtual bool impl(const string &a, const string &b) const {
if (a.length() == b.length()) {
bool equal = (strncasecmp(a.c_str(), b.c_str(), a.length()) == 0);
return equal;
}
else {
} else {
return false;
}
}

View File

@ -4,7 +4,7 @@
#include <gtest/gtest.h>
int main (int argc, char *argv[]) {
int main(int argc, char *argv[]) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@ -1,27 +1,30 @@
#include "dtl_test_common.hpp"
string create_path (const string& test_name, string diff_name, enum type_diff t, bool is_use_suffix) {
string create_path(const string &test_name, string diff_name, enum type_diff t,
bool is_use_suffix) {
string ret;
switch (t) {
case TYPE_DIFF_SES:
ret = (getcwd(NULL, 0) + string("/") + string("ses") + string("/") + diff_name + string("/") + test_name);
ret = (getcwd(NULL, 0) + string("/") + string("ses") + string("/") +
diff_name + string("/") + test_name);
break;
case TYPE_DIFF_UNI:
ret = (getcwd(NULL, 0) + string("/") + string("hunks") + string("/") + diff_name + string("/") + test_name);
ret = (getcwd(NULL, 0) + string("/") + string("hunks") + string("/") +
diff_name + string("/") + test_name);
break;
}
ret += is_use_suffix ? "_" : "";
return ret;
}
size_t cal_diff_uni (const string& path_l, const string& path_r) {
size_t cal_diff_uni(const string &path_l, const string &path_r) {
string buf;
ifstream lifs(path_l.c_str());
ifstream rifs(path_r.c_str());
vector< string > llines;
vector< string > rlines;
vector<string> llines;
vector<string> rlines;
while (getline(lifs, buf)) {
llines.push_back(buf);
@ -31,12 +34,12 @@ size_t cal_diff_uni (const string& path_l, const string& path_r) {
rlines.push_back(buf);
}
Diff< string, vector< string > > diff_uni(llines, rlines);
Diff<string, vector<string>> diff_uni(llines, rlines);
diff_uni.compose();
return diff_uni.getEditDistance();
}
bool is_file_exist (string& fs) {
bool is_file_exist(string &fs) {
FILE *fp;
if ((fp = fopen(fs.c_str(), "r")) == NULL) {
return false;
@ -45,11 +48,15 @@ bool is_file_exist (string& fs) {
return true;
}
void diff_resultset_exist_check (string &fs) {
void diff_resultset_exist_check(string &fs) {
if (!is_file_exist(fs)) {
cerr << "======================================================Error!!!======================================================" << endl;
cerr << "======================================================Error!!!===="
"=================================================="
<< endl;
cerr << "diff result set:" << fs << " is not found." << endl;
cerr << "======================================================Error!!!======================================================" << endl;
cerr << "======================================================Error!!!===="
"=================================================="
<< endl;
cerr << "excute dtl_test in dtl/test!" << endl;
exit(EXIT_FAILURE);
}

View File

@ -2,58 +2,59 @@
#ifndef DTL_TEST_COMMON
#define DTL_TEST_COMMON
#include <gtest/gtest.h>
#include <cstdio>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <fstream>
#include <dtl/dtl.hpp>
#include <fstream>
#include <gtest/gtest.h>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using std::cerr;
using std::endl;
using std::string;
using std::vector;
using std::pair;
using std::ifstream;
using std::ofstream;
using std::pair;
using std::string;
using std::vector;
using dtl::Compare;
using dtl::Diff;
using dtl::Diff3;
using dtl::Compare;
using dtl::SES_COMMON;
using dtl::SES_ADD;
using dtl::SES_DELETE;
using dtl::elemInfo;
using dtl::SES_ADD;
using dtl::SES_COMMON;
using dtl::SES_DELETE;
using dtl::uniHunk;
#define dtl_test_typedefs(e_type, seq_type) \
typedef e_type elem; \
typedef seq_type sequence; \
typedef pair< elem, elemInfo > sesElem; \
typedef vector< elem > elemVec; \
typedef vector< sesElem > sesElemVec; \
typedef vector< uniHunk< sesElem > > uniHunkVec;
typedef pair<elem, elemInfo> sesElem; \
typedef vector<elem> elemVec; \
typedef vector<sesElem> sesElemVec; \
typedef vector<uniHunk<sesElem>> uniHunkVec;
enum type_diff { TYPE_DIFF_SES, TYPE_DIFF_UNI };
string create_path (const string& test_name, string diff_name, enum type_diff t, bool is_use_suffix = false);
size_t cal_diff_uni (const string& path_l, const string& path_r);
bool is_file_exist (string& fs);
void diff_resultset_exist_check (string &fs);
string create_path(const string &test_name, string diff_name, enum type_diff t,
bool is_use_suffix = false);
size_t cal_diff_uni(const string &path_l, const string &path_r);
bool is_file_exist(string &fs);
void diff_resultset_exist_check(string &fs);
template <typename T>
class Remover {
public :
void operator()(const T& v){
template <typename T> class Remover {
public:
void operator()(const T &v) {
remove(v.path_rses.c_str());
remove(v.path_rhunks.c_str());
}
};
template < typename elem, typename sequence, typename comparator >
void create_file (const string& path, Diff< elem, sequence, comparator >& diff, enum type_diff t) {
template <typename elem, typename sequence, typename comparator>
void create_file(const string &path, Diff<elem, sequence, comparator> &diff,
enum type_diff t) {
ofstream ofs;
ofs.open(path.c_str());
switch (t) {