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> 2022-04-11 Tatsuhiko Kubo <cubicdaiya@gmail.com>
* bugfix: fixed invalid offset in unified format difference when difference is too large. * bugfix: fixed invalid offset in unified format difference when difference is too large.

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +1,25 @@
/** /**
dtl -- Diff Template Library dtl -- Diff Template Library
In short, Diff Template Library is distributed under so called "BSD license", In short, Diff Template Library is distributed under so called "BSD license",
Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com> Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without
are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, * Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
* Neither the name of the authors nor the names of its contributors * Neither the name of the authors nor the names of its contributors
may be used to endorse or promote products derived from this software may be used to endorse or promote products derived from this software
without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@ -39,207 +39,203 @@
#define DTL_DIFF3_H #define DTL_DIFF3_H
namespace dtl { namespace dtl {
/** /**
* diff3 class template * diff3 class template
* sequence must support random_access_iterator. * sequence must support random_access_iterator.
*/ */
template <typename elem, typename sequence = vector< elem >, typename comparator = Compare< elem > > template <typename elem, typename sequence = vector<elem>,
class Diff3 typename comparator = Compare<elem>>
{ class Diff3 {
private: private:
dtl_typedefs(elem, sequence) dtl_typedefs(elem, sequence) sequence A;
sequence A; sequence B;
sequence B; sequence C;
sequence C; sequence S;
sequence S; Diff<elem, sequence, comparator> diff_ba;
Diff< elem, sequence, comparator > diff_ba; Diff<elem, sequence, comparator> diff_bc;
Diff< elem, sequence, comparator > diff_bc; bool conflict;
bool conflict; elem csepabegin;
elem csepabegin; elem csepa;
elem csepa; elem csepaend;
elem csepaend;
public : public:
Diff3 () {} Diff3() {}
Diff3 (const sequence& a, Diff3(const sequence &a, const sequence &b, const sequence &c)
const sequence& b, : A(a), B(b), C(c), diff_ba(b, a), diff_bc(b, c), conflict(false) {}
const sequence& c) : A(a), B(b), C(c),
diff_ba(b, a), diff_bc(b, c), ~Diff3() {}
conflict(false) {}
bool isConflict() const { return conflict; }
~Diff3 () {}
sequence getMergedSequence() const { return S; }
bool isConflict () const {
return conflict; /**
* merge changes B and C into A
*/
bool merge() {
if (diff_ba.getEditDistance() == 0) { // A == B
if (diff_bc.getEditDistance() == 0) { // A == B == C
S = B;
return true;
}
S = C;
return true;
} else { // A != B
if (diff_bc.getEditDistance() == 0) { // A != B == C
S = A;
return true;
} else { // A != B != C
S = merge_();
if (isConflict()) { // conflict occured
return false;
} }
}
sequence getMergedSequence () const { }
return S; return true;
}
/**
* compose differences
*/
void compose() {
diff_ba.compose();
diff_bc.compose();
}
private:
/**
* merge implementation
*/
sequence merge_() {
elemVec seq;
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();
sesElemVec_iter bc_it = ses_bc_v.begin();
sesElemVec_iter ba_end = ses_ba_v.end();
sesElemVec_iter bc_end = ses_bc_v.end();
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 &&
bc_it->second.type == SES_COMMON) {
// do nothing
} else {
break;
} }
if (!isEnd(ba_end, ba_it))
/** seq.push_back(ba_it->first);
* merge changes B and C into A else if (!isEnd(bc_end, bc_it))
*/ seq.push_back(bc_it->first);
bool merge () { forwardUntilEnd(ba_end, ba_it);
if (diff_ba.getEditDistance() == 0) { // A == B forwardUntilEnd(bc_end, bc_it);
if (diff_bc.getEditDistance() == 0) { // A == B == C }
S = B; if (isEnd(ba_end, ba_it) || isEnd(bc_end, bc_it))
return true; break;
} if (ba_it->second.type == SES_COMMON &&
S = C; bc_it->second.type == SES_DELETE) {
return true; forwardUntilEnd(ba_end, ba_it);
} else { // A != B forwardUntilEnd(bc_end, bc_it);
if (diff_bc.getEditDistance() == 0) { // A != B == C } else if (ba_it->second.type == SES_COMMON &&
S = A; bc_it->second.type == SES_ADD) {
return true; seq.push_back(bc_it->first);
} else { // A != B != C forwardUntilEnd(bc_end, bc_it);
S = merge_(); } else if (ba_it->second.type == SES_DELETE &&
if (isConflict()) { // conflict occured bc_it->second.type == SES_COMMON) {
return false; forwardUntilEnd(ba_end, ba_it);
} forwardUntilEnd(bc_end, bc_it);
} } else if (ba_it->second.type == SES_DELETE &&
} bc_it->second.type == SES_DELETE) {
return true; if (ba_it->first == bc_it->first) {
forwardUntilEnd(ba_end, ba_it);
forwardUntilEnd(bc_end, bc_it);
} else {
// conflict
conflict = true;
return B;
} }
} else if (ba_it->second.type == SES_DELETE &&
/** bc_it->second.type == SES_ADD) {
* compose differences // conflict
*/ conflict = true;
void compose () { return B;
diff_ba.compose(); } else if (ba_it->second.type == SES_ADD &&
diff_bc.compose(); bc_it->second.type == SES_COMMON) {
seq.push_back(ba_it->first);
forwardUntilEnd(ba_end, ba_it);
} else if (ba_it->second.type == SES_ADD &&
bc_it->second.type == SES_DELETE) {
// conflict
conflict = true;
return B;
} else if (ba_it->second.type == SES_ADD &&
bc_it->second.type == SES_ADD) {
if (ba_it->first == bc_it->first) {
seq.push_back(ba_it->first);
forwardUntilEnd(ba_end, ba_it);
forwardUntilEnd(bc_end, bc_it);
} else {
// conflict
conflict = true;
return B;
} }
}
private : }
/**
* merge implementation if (isEnd(ba_end, ba_it)) {
*/ addDecentSequence(bc_end, bc_it, seq);
sequence merge_ () { } else if (isEnd(bc_end, bc_it)) {
elemVec seq; addDecentSequence(ba_end, ba_it, seq);
Ses< elem > ses_ba = diff_ba.getSes(); }
Ses< elem > ses_bc = diff_bc.getSes();
sesElemVec ses_ba_v = ses_ba.getSequence(); sequence mergedSeq(seq.begin(), seq.end());
sesElemVec ses_bc_v = ses_bc.getSequence(); return mergedSeq;
sesElemVec_iter ba_it = ses_ba_v.begin(); }
sesElemVec_iter bc_it = ses_bc_v.begin();
sesElemVec_iter ba_end = ses_ba_v.end(); /**
sesElemVec_iter bc_end = ses_bc_v.end(); * join elem vectors
*/
while (!isEnd(ba_end, ba_it) || !isEnd(bc_end, bc_it)) { void inline joinElemVec(elemVec &s1, elemVec &s2) const {
while (true) { if (!s2.empty()) {
if (!isEnd(ba_end, ba_it) && for (elemVec_iter vit = s2.begin(); vit != s2.end(); ++vit) {
!isEnd(bc_end, bc_it) && s1.push_back(*vit);
ba_it->first == bc_it->first && }
ba_it->second.type == SES_COMMON && }
bc_it->second.type == SES_COMMON) { }
// do nothing
} else { /**
break; * check if sequence is at end
} */
if (!isEnd(ba_end, ba_it)) seq.push_back(ba_it->first); template <typename T_iter>
else if (!isEnd(bc_end, bc_it)) seq.push_back(bc_it->first); bool inline isEnd(const T_iter &end, const T_iter &it) const {
forwardUntilEnd(ba_end, ba_it); return it == end ? true : false;
forwardUntilEnd(bc_end, bc_it); }
}
if (isEnd(ba_end, ba_it) || isEnd(bc_end, bc_it)) break; /**
if ( ba_it->second.type == SES_COMMON * increment iterator until iterator is at end
&& bc_it->second.type == SES_DELETE) { */
forwardUntilEnd(ba_end, ba_it); template <typename T_iter>
forwardUntilEnd(bc_end, bc_it); void inline forwardUntilEnd(const T_iter &end, T_iter &it) const {
} else if (ba_it->second.type == SES_COMMON && if (!isEnd(end, it))
bc_it->second.type == SES_ADD) { ++it;
seq.push_back(bc_it->first); }
forwardUntilEnd(bc_end, bc_it);
} else if (ba_it->second.type == SES_DELETE && /**
bc_it->second.type == SES_COMMON) { * add elements whose SES's type is ADD
forwardUntilEnd(ba_end, ba_it); */
forwardUntilEnd(bc_end, bc_it); void inline addDecentSequence(const sesElemVec_iter &end, sesElemVec_iter &it,
} else if (ba_it->second.type == SES_DELETE && elemVec &seq) const {
bc_it->second.type == SES_DELETE) { while (!isEnd(end, it)) {
if (ba_it->first == bc_it->first) { if (it->second.type == SES_ADD)
forwardUntilEnd(ba_end, ba_it); seq.push_back(it->first);
forwardUntilEnd(bc_end, bc_it); ++it;
} else { }
// conflict }
conflict = true; };
return B; } // namespace dtl
}
} else if (ba_it->second.type == SES_DELETE &&
bc_it->second.type == SES_ADD) {
// conflict
conflict = true;
return B;
} else if (ba_it->second.type == SES_ADD &&
bc_it->second.type == SES_COMMON) {
seq.push_back(ba_it->first);
forwardUntilEnd(ba_end, ba_it);
} else if (ba_it->second.type == SES_ADD &&
bc_it->second.type == SES_DELETE) {
// conflict
conflict = true;
return B;
} else if (ba_it->second.type == SES_ADD &&
bc_it->second.type == SES_ADD) {
if (ba_it->first == bc_it->first) {
seq.push_back(ba_it->first);
forwardUntilEnd(ba_end, ba_it);
forwardUntilEnd(bc_end, bc_it);
} else {
// conflict
conflict = true;
return B;
}
}
}
if (isEnd(ba_end, ba_it)) {
addDecentSequence(bc_end, bc_it, seq);
} else if (isEnd(bc_end, bc_it)) {
addDecentSequence(ba_end, ba_it, seq);
}
sequence mergedSeq(seq.begin(), seq.end());
return mergedSeq;
}
/**
* join elem vectors
*/
void inline joinElemVec (elemVec& s1, elemVec& s2) const {
if (!s2.empty()) {
for (elemVec_iter vit=s2.begin();vit!=s2.end();++vit) {
s1.push_back(*vit);
}
}
}
/**
* check if sequence is at end
*/
template <typename T_iter>
bool inline isEnd (const T_iter& end, const T_iter& it) const {
return it == end ? true : false;
}
/**
* 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;
}
/**
* add elements whose SES's type is ADD
*/
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);
++it;
}
}
};
}
#endif // DTL_DIFF3_H #endif // DTL_DIFF3_H

View File

@ -1,25 +1,25 @@
/** /**
dtl -- Diff Template Library dtl -- Diff Template Library
In short, Diff Template Library is distributed under so called "BSD license", In short, Diff Template Library is distributed under so called "BSD license",
Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com> Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without
are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, * Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
* Neither the name of the authors nor the names of its contributors * Neither the name of the authors nor the names of its contributors
may be used to endorse or promote products derived from this software may be used to endorse or promote products derived from this software
without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@ -39,17 +39,15 @@
#define DTL_LCS_H #define DTL_LCS_H
namespace dtl { namespace dtl {
/** /**
* Longest Common Subsequence template class * Longest Common Subsequence template class
*/ */
template <typename elem> template <typename elem> class Lcs : public Sequence<elem> {
class Lcs : public Sequence< elem > public:
{ Lcs() {}
public : ~Lcs() {}
Lcs () {} };
~Lcs () {} } // namespace dtl
};
}
#endif // DTL_LCS_H #endif // DTL_LCS_H

View File

@ -1,25 +1,25 @@
/** /**
dtl -- Diff Template Library dtl -- Diff Template Library
In short, Diff Template Library is distributed under so called "BSD license", In short, Diff Template Library is distributed under so called "BSD license",
Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com> Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without
are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, * Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
* Neither the name of the authors nor the names of its contributors * Neither the name of the authors nor the names of its contributors
may be used to endorse or promote products derived from this software may be used to endorse or promote products derived from this software
without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@ -39,27 +39,22 @@
#define DTL_SEQUENCE_H #define DTL_SEQUENCE_H
namespace dtl { namespace dtl {
/** /**
* sequence class template * sequence class template
*/ */
template <typename elem> template <typename elem> class Sequence {
class Sequence public:
{ typedef vector<elem> elemVec;
public : Sequence() {}
typedef vector< elem > elemVec; virtual ~Sequence() {}
Sequence () {}
virtual ~Sequence () {} elemVec getSequence() const { return sequence; }
void addSequence(elem e) { sequence.push_back(e); }
elemVec getSequence () const {
return sequence; protected:
} elemVec sequence;
void addSequence (elem e) { };
sequence.push_back(e); } // namespace dtl
}
protected :
elemVec sequence;
};
}
#endif // DTL_SEQUENCE_H #endif // DTL_SEQUENCE_H

View File

@ -1,25 +1,25 @@
/** /**
dtl -- Diff Template Library dtl -- Diff Template Library
In short, Diff Template Library is distributed under so called "BSD license", In short, Diff Template Library is distributed under so called "BSD license",
Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com> Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without
are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, * Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
* Neither the name of the authors nor the names of its contributors * Neither the name of the authors nor the names of its contributors
may be used to endorse or promote products derived from this software may be used to endorse or promote products derived from this software
without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@ -39,94 +39,85 @@
#define DTL_SES_H #define DTL_SES_H
namespace dtl { namespace dtl {
/** /**
* Shortest Edit Script template class * Shortest Edit Script template class
*/ */
template <typename elem> template <typename elem> class Ses : public Sequence<elem> {
class Ses : public Sequence< elem > private:
{ typedef pair<elem, elemInfo> sesElem;
private : typedef vector<sesElem> sesElemVec;
typedef pair< elem, elemInfo > sesElem;
typedef vector< sesElem > sesElemVec; public:
public : Ses() : onlyAdd(true), onlyDelete(true), onlyCopy(true), deletesFirst(false) {
nextDeleteIdx = 0;
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;
nextDeleteIdx = 0; }
} ~Ses() {}
~Ses () {}
bool isOnlyAdd() const { return onlyAdd; }
bool isOnlyAdd () const {
return onlyAdd; bool isOnlyDelete() const { return onlyDelete; }
}
bool isOnlyCopy() const { return onlyCopy; }
bool isOnlyDelete () const {
return onlyDelete; bool isOnlyOneOperation() const {
} return isOnlyAdd() || isOnlyDelete() || isOnlyCopy();
}
bool isOnlyCopy () const {
return onlyCopy; bool isChange() const { return !onlyCopy; }
}
using Sequence<elem>::addSequence;
bool isOnlyOneOperation () const { void addSequence(elem e, long long beforeIdx, long long afterIdx,
return isOnlyAdd() || isOnlyDelete() || isOnlyCopy(); const edit_t type) {
} elemInfo info;
info.beforeIdx = beforeIdx;
bool isChange () const { info.afterIdx = afterIdx;
return !onlyCopy; info.type = type;
} sesElem pe(e, info);
if (!deletesFirst) {
using Sequence< elem >::addSequence; sequence.push_back(pe);
void addSequence (elem e, long long beforeIdx, long long afterIdx, const edit_t type) { }
elemInfo info; switch (type) {
info.beforeIdx = beforeIdx; case SES_DELETE:
info.afterIdx = afterIdx; onlyCopy = false;
info.type = type; onlyAdd = false;
sesElem pe(e, info); if (deletesFirst) {
if (!deletesFirst) { sequence.insert(sequence.begin() + nextDeleteIdx, pe);
sequence.push_back(pe); nextDeleteIdx++;
} }
switch (type) { break;
case SES_DELETE: case SES_COMMON:
onlyCopy = false; onlyAdd = false;
onlyAdd = false; onlyDelete = false;
if (deletesFirst) { if (deletesFirst) {
sequence.insert(sequence.begin() + nextDeleteIdx, pe); sequence.push_back(pe);
nextDeleteIdx++; nextDeleteIdx = sequence.size();
} }
break; break;
case SES_COMMON: case SES_ADD:
onlyAdd = false; onlyDelete = false;
onlyDelete = false; onlyCopy = false;
if (deletesFirst) { if (deletesFirst) {
sequence.push_back(pe); sequence.push_back(pe);
nextDeleteIdx = sequence.size(); }
} break;
break; }
case SES_ADD: }
onlyDelete = false;
onlyCopy = false; sesElemVec getSequence() const { return sequence; }
if (deletesFirst) {
sequence.push_back(pe); private:
} sesElemVec sequence;
break; bool onlyAdd;
} bool onlyDelete;
} bool onlyCopy;
bool deletesFirst;
sesElemVec getSequence () const { size_t nextDeleteIdx;
return sequence; };
} } // namespace dtl
private :
sesElemVec sequence;
bool onlyAdd;
bool onlyDelete;
bool onlyCopy;
bool deletesFirst;
size_t nextDeleteIdx;
};
}
#endif // DTL_SES_H #endif // DTL_SES_H

View File

@ -1,25 +1,25 @@
/** /**
dtl -- Diff Template Library dtl -- Diff Template Library
In short, Diff Template Library is distributed under so called "BSD license", In short, Diff Template Library is distributed under so called "BSD license",
Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com> Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without
are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, * Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
* Neither the name of the authors nor the names of its contributors * Neither the name of the authors nor the names of its contributors
may be used to endorse or promote products derived from this software may be used to endorse or promote products derived from this software
without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@ -36,12 +36,12 @@
#ifndef DTL_H #ifndef DTL_H
#define DTL_H #define DTL_H
#include "variables.hpp"
#include "functors.hpp"
#include "Sequence.hpp"
#include "Lcs.hpp"
#include "Ses.hpp"
#include "Diff.hpp" #include "Diff.hpp"
#include "Diff3.hpp" #include "Diff3.hpp"
#include "Lcs.hpp"
#include "Sequence.hpp"
#include "Ses.hpp"
#include "functors.hpp"
#include "variables.hpp"
#endif // DTL_H #endif // DTL_H

View File

@ -1,25 +1,25 @@
/** /**
dtl -- Diff Template Library dtl -- Diff Template Library
In short, Diff Template Library is distributed under so called "BSD license", In short, Diff Template Library is distributed under so called "BSD license",
Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com> Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without
are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, * Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
* Neither the name of the authors nor the names of its contributors * Neither the name of the authors nor the names of its contributors
may be used to endorse or promote products derived from this software may be used to endorse or promote products derived from this software
without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@ -39,113 +39,108 @@
#define DTL_FUNCTORS_H #define DTL_FUNCTORS_H
namespace dtl { 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_;
};
/**
* 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 {
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 {
switch (se.second.type) {
case SES_ADD:
this->out_ << SES_MARK_ADD << se.first << endl;
break;
case SES_DELETE:
this->out_ << SES_MARK_DELETE << se.first << endl;
break;
case SES_COMMON:
this->out_ << SES_MARK_COMMON << se.first << endl;
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 {
out_ << "@@"
<< " -" << 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_));
}
private :
stream& out_;
};
/** /**
* storage class template * printer class template
*/ */
template <typename sesElem, typename storedData > template <typename sesElem, typename stream = ostream> class Printer {
class Storage public:
{ Printer() : out_(cout) {}
public: Printer(stream &out) : out_(out) {}
Storage(storedData& sd) : storedData_(sd) {} virtual ~Printer() {}
virtual ~Storage() {} virtual void operator()(const sesElem &se) const = 0;
virtual void operator() (const sesElem& se) const = 0;
protected: protected:
storedData& storedData_; stream &out_;
}; };
/** /**
* compare class template * common element printer class template
*/ */
template <typename elem> template <typename sesElem, typename stream = ostream>
class Compare class CommonPrinter : public Printer<sesElem, stream> {
{ public:
public : CommonPrinter() : Printer<sesElem, stream>() {}
Compare () {} CommonPrinter(stream &out) : Printer<sesElem, stream>(out) {}
virtual ~Compare () {} ~CommonPrinter() {}
virtual inline bool impl (const elem& e1, const elem& e2) const { void operator()(const sesElem &se) const {
return e1 == e2; 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 {
switch (se.second.type) {
case SES_ADD:
this->out_ << SES_MARK_ADD << se.first << endl;
break;
case SES_DELETE:
this->out_ << SES_MARK_DELETE << se.first << endl;
break;
case SES_COMMON:
this->out_ << SES_MARK_COMMON << se.first << endl;
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 {
out_ << "@@"
<< " -" << 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_));
}
private:
stream &out_;
};
/**
* storage class template
*/
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_;
};
/**
* compare class template
*/
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 #endif // DTL_FUNCTORS_H

View File

@ -1,25 +1,25 @@
/** /**
dtl -- Diff Template Library dtl -- Diff Template Library
In short, Diff Template Library is distributed under so called "BSD license", In short, Diff Template Library is distributed under so called "BSD license",
Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com> Copyright (c) 2015 Tatsuhiko Kubo <cubicdaiya@gmail.com>
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, Redistribution and use in source and binary forms, with or without
are permitted provided that the following conditions are met: modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, * Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, * Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution. and/or other materials provided with the distribution.
* Neither the name of the authors nor the names of its contributors * Neither the name of the authors nor the names of its contributors
may be used to endorse or promote products derived from this software may be used to endorse or promote products derived from this software
without specific prior written permission. without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@ -38,105 +38,104 @@
#ifndef DTL_VARIABLES_H #ifndef DTL_VARIABLES_H
#define DTL_VARIABLES_H #define DTL_VARIABLES_H
#include <vector>
#include <list>
#include <string>
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
#include <list>
#include <string>
#include <vector>
namespace dtl { 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;
* version string using std::distance;
*/ using std::endl;
const string version = "1.20"; 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;
/** /**
* type of edit for SES * version string
*/ */
typedef int edit_t; const string version = "1.21";
const edit_t SES_DELETE = -1;
const edit_t SES_COMMON = 0; /**
const edit_t SES_ADD = 1; * type of edit for SES
*/
/** typedef int edit_t;
* mark of SES 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_DELETE "-"
#define SES_MARK_COMMON " " #define SES_MARK_COMMON " "
#define SES_MARK_ADD "+" #define SES_MARK_ADD "+"
/** /**
* info for Unified Format * info for Unified Format
*/ */
typedef struct eleminfo { typedef struct eleminfo {
long long beforeIdx; // index of prev sequence long long beforeIdx; // index of prev sequence
long long afterIdx; // index of after sequence long long afterIdx; // index of after sequence
edit_t type; // type of edit(Add, Delete, Common) edit_t type; // type of edit(Add, Delete, Common)
bool operator==(const eleminfo& other) const{ bool operator==(const eleminfo &other) const {
return (this->beforeIdx == other.beforeIdx && this->afterIdx == other.afterIdx && this->type == other.type); 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;
/**
* cordinate for registering route
*/
typedef struct Point {
long long x; // x cordinate
long long y; // y cordinate
long long k; // vertex
} P;
/**
* limit of cordinate size
*/
const unsigned long long MAX_CORDINATES_SIZE = 2000000;
typedef vector< long long > editPath;
typedef vector< P > editPathCordinates;
/**
* Structure of Unified Format Hunk
*/
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
long long inc_dec_count; // count of increace and decrease
};
#define dtl_typedefs(elem, sequence) \ const long long DTL_SEPARATE_SIZE = 3;
typedef pair< elem, elemInfo > sesElem; \ const long long DTL_CONTEXT_SIZE = 3;
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; \
typedef typename sequence::iterator sequence_iter; \
typedef typename sequence::const_iterator sequence_const_iter; \
typedef typename elemVec::iterator elemVec_iter;
/**
* cordinate for registering route
*/
typedef struct Point {
long long x; // x cordinate
long long y; // y cordinate
long long k; // vertex
} P;
} /**
* limit of cordinate size
*/
const unsigned long long MAX_CORDINATES_SIZE = 2000000;
typedef vector<long long> editPath;
typedef vector<P> editPathCordinates;
/**
* Structure of Unified Format Hunk
*/
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
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 typename uniHunkVec::iterator uniHunkVec_iter; \
typedef typename sesElemVec::iterator sesElemVec_iter; \
typedef typename elemList::iterator elemList_iter; \
typedef typename sequence::iterator sequence_iter; \
typedef typename sequence::const_iterator sequence_const_iter; \
typedef typename elemVec::iterator elemVec_iter;
} // namespace dtl
#endif // DTL_VARIABLES_H #endif // DTL_VARIABLES_H

View File

@ -1,14 +1,14 @@
#include <dtl/dtl.hpp>
#include "common.hpp" #include "common.hpp"
#include <dtl/dtl.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <cstdio> #include <cstdio>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <iostream>
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
#include <vector>
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif // HAVE_UNISTD_H #endif // HAVE_UNISTD_H
@ -17,57 +17,55 @@ using namespace std;
using dtl::Diff; using dtl::Diff;
typedef unsigned char elem; 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 fd; int siz;
int siz; elem buf[BUFSIZ];
elem buf[BUFSIZ]; if ((fd = open(fs, O_RDONLY)) == -1) {
if ((fd = open(fs, O_RDONLY)) == -1) { cout << "Opening failed." << endl;
cout << "Opening failed." << endl; return -1;
return -1; }
} while ((siz = read(fd, buf, sizeof(buf))) > 0) {
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]);
seq.push_back(buf[i]);
}
}
if (siz < 0) {
close(fd);
cout << "Read error." << endl;
return -1;
} }
}
if (siz < 0) {
close(fd); close(fd);
return 0; cout << "Read error." << endl;
return -1;
}
close(fd);
return 0;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[]) {
{
if (isFewArgs(argc)) {
cerr << "Too few arguments." << endl;
return -1;
}
string fs1(argv[1]);
string fs2(argv[2]);
sequence seq1;
sequence seq2;
create_byte_seq(fs1.c_str(), seq1);
create_byte_seq(fs2.c_str(), seq2);
Diff< elem, sequence > d(seq1, seq2);
d.compose();
if (d.getEditDistance() == 0) { if (isFewArgs(argc)) {
cout << fs1 << " is the same as " << fs2 << endl; cerr << "Too few arguments." << endl;
} else { return -1;
cout << fs1 << " is different from " << fs2 << endl; }
}
string fs1(argv[1]);
return 0; string fs2(argv[2]);
sequence seq1;
sequence seq2;
create_byte_seq(fs1.c_str(), seq1);
create_byte_seq(fs2.c_str(), seq2);
Diff<elem, sequence> d(seq1, seq2);
d.compose();
if (d.getEditDistance() == 0) {
cout << fs1 << " is the same as " << fs2 << endl;
} else {
cout << fs1 << " is different from " << fs2 << endl;
}
return 0;
} }

View File

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

View File

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

View File

@ -1,73 +1,73 @@
#include <dtl/dtl.hpp>
#include "common.hpp" #include "common.hpp"
#include <cassert>
#include <dtl/dtl.hpp>
#include <fstream>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <fstream>
#include <vector> #include <vector>
#include <cassert>
using namespace std; using namespace std;
using dtl::Diff; using dtl::Diff;
int main(int argc, char *argv[]){ int main(int argc, char *argv[]) {
if (isFewArgs(argc)) {
cerr << "Too few arguments." << endl;
return -1;
}
string A(argv[1]);
string B(argv[2]);
bool fileExist = true;
if (!isFileExist(A)) {
cerr << "file A does not exist" << endl;
fileExist = false;
}
if (!isFileExist(B)) {
cerr << "file B does not exist" << endl;
fileExist = false;
}
if (!fileExist) {
return -1;
}
typedef string elem;
typedef vector< elem > sequence;
ifstream Aifs(A.c_str()); if (isFewArgs(argc)) {
ifstream Bifs(B.c_str()); cerr << "Too few arguments." << endl;
elem buf; return -1;
sequence ALines, BLines; }
ostringstream ossLine, ossInfo;
string A(argv[1]);
while(getline(Aifs, buf)){ string B(argv[2]);
ALines.push_back(buf); bool fileExist = true;
}
while(getline(Bifs, buf)){ if (!isFileExist(A)) {
BLines.push_back(buf); cerr << "file A does not exist" << endl;
} fileExist = false;
}
Diff< elem > d(ALines, BLines);
d.compose(); if (!isFileExist(B)) {
cerr << "file B does not exist" << endl;
sequence s1 = ALines; fileExist = false;
sequence s2 = d.patch(s1); }
// fpatch if (!fileExist) {
assert(BLines == s2); return -1;
cout << "fpatch succeeded" << endl; }
d.composeUnifiedHunks(); typedef string elem;
sequence s3 = d.uniPatch(s1); typedef vector<elem> sequence;
// unipatch ifstream Aifs(A.c_str());
assert(BLines == s3); ifstream Bifs(B.c_str());
cout << "unipatch succeeded" << endl; elem buf;
sequence ALines, BLines;
return 0; ostringstream ossLine, ossInfo;
while (getline(Aifs, buf)) {
ALines.push_back(buf);
}
while (getline(Bifs, buf)) {
BLines.push_back(buf);
}
Diff<elem> d(ALines, BLines);
d.compose();
sequence s1 = ALines;
sequence s2 = d.patch(s1);
// fpatch
assert(BLines == s2);
cout << "fpatch succeeded" << endl;
d.composeUnifiedHunks();
sequence s3 = d.uniPatch(s1);
// unipatch
assert(BLines == s3);
cout << "unipatch succeeded" << endl;
return 0;
} }

View File

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

View File

@ -1,57 +1,57 @@
#include <cassert>
#include <dtl/dtl.hpp> #include <dtl/dtl.hpp>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <cassert>
using namespace std; using namespace std;
using dtl::Diff3; 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 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}; int b[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int c[10] = {1, 2, 3, 9, 5, 6, 7, 8, 9, 10}; int c[10] = {1, 2, 3, 9, 5, 6, 7, 8, 9, 10};
int answer[10] = {1, 2, 3, 9, 5, 6, 7, 3, 9, 10}; int answer[10] = {1, 2, 3, 9, 5, 6, 7, 3, 9, 10};
cout << "a:"; cout << "a:";
for (int i=0;i<10;++i) { for (int i = 0; i < 10; ++i) {
cout << a[i] << " "; cout << a[i] << " ";
} }
cout << endl; cout << endl;
cout << "b:"; cout << "b:";
for (int i=0;i<10;++i) { for (int i = 0; i < 10; ++i) {
cout << b[i] << " "; cout << b[i] << " ";
} }
cout << endl; cout << endl;
cout << "c:"; cout << "c:";
for (int i=0;i<10;++i) { for (int i = 0; i < 10; ++i) {
cout << c[i] << " "; cout << c[i] << " ";
} }
cout << endl; cout << endl;
typedef int elem; typedef int elem;
typedef vector< int > sequence; typedef vector<int> sequence;
sequence A(&a[0], &a[10]); sequence A(&a[0], &a[10]);
sequence B(&b[0], &b[10]); sequence B(&b[0], &b[10]);
sequence C(&c[0], &c[10]); sequence C(&c[0], &c[10]);
sequence Answer(&answer[0], &answer[10]); sequence Answer(&answer[0], &answer[10]);
Diff3< elem > diff3(A, B, C); Diff3<elem> diff3(A, B, C);
diff3.compose(); diff3.compose();
if (!diff3.merge()) { if (!diff3.merge()) {
cerr << "conflict." << endl; cerr << "conflict." << endl;
return -1; return -1;
} }
sequence s = diff3.getMergedSequence(); sequence s = diff3.getMergedSequence();
cout << "s:"; 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 << *it << " ";
} }
cout << endl; cout << endl;
assert(s == Answer); assert(s == Answer);
cout << "intdiff3 OK" << endl; cout << "intdiff3 OK" << endl;
return 0; return 0;
} }

View File

@ -1,44 +1,44 @@
#include <dtl/dtl.hpp>
#include "common.hpp" #include "common.hpp"
#include <cassert>
#include <dtl/dtl.hpp>
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#include <cassert>
using namespace std; using namespace std;
using dtl::Diff; using dtl::Diff;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
if (isFewArgs(argc)) {
cerr << "Too few arguments." << endl;
return -1;
}
typedef char elem;
typedef string sequence;
sequence A(argv[1]); if (isFewArgs(argc)) {
sequence B(argv[2]); cerr << "Too few arguments." << endl;
return -1;
Diff< elem, sequence > d(A, B); }
d.compose();
typedef char elem;
sequence s1(A); typedef string sequence;
sequence s2 = d.patch(s1);
d.composeUnifiedHunks(); sequence A(argv[1]);
sequence s3 = d.uniPatch(s1); sequence B(argv[2]);
cout << "before:" << s1 << endl; Diff<elem, sequence> d(A, B);
cout << "after :" << s2 << endl; d.compose();
assert(B == s2);
cout << "patch succeeded" << endl; sequence s1(A);
sequence s2 = d.patch(s1);
cout << "before:" << s1 << endl; d.composeUnifiedHunks();
cout << "after :" << s3 << endl; sequence s3 = d.uniPatch(s1);
assert(B == s3);
cout << "unipatch succeeded" << endl; cout << "before:" << s1 << endl;
cout << "after :" << s2 << endl;
return 0; assert(B == s2);
cout << "patch succeeded" << endl;
cout << "before:" << s1 << endl;
cout << "after :" << s3 << endl;
assert(B == s3);
cout << "unipatch succeeded" << endl;
return 0;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,13 +1,13 @@
#include <dtl/dtl.hpp>
#include "common.hpp" #include "common.hpp"
#include <iostream> #include <dtl/dtl.hpp>
#include <fstream> #include <fstream>
#include <iostream>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
#include <time.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <time.h>
using namespace std; using namespace std;
@ -15,97 +15,93 @@ using dtl::Diff;
using dtl::elemInfo; using dtl::elemInfo;
using dtl::uniHunk; using dtl::uniHunk;
static void showStats (string fp1, string fp2); static void showStats(string fp1, string fp2);
static void unifiedDiff (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;
const int MAX_LENGTH = 255; char time_format[] = "%Y-%m-%d %H:%M:%S %z";
char time_format[] = "%Y-%m-%d %H:%M:%S %z"; time_t rawtime[2];
time_t rawtime[2]; struct tm *timeinfo[2];
struct tm *timeinfo[2]; struct stat st[2];
struct stat st[2];
if (stat(fp1.c_str(), &st[0]) == -1) {
if (stat(fp1.c_str(), &st[0]) == -1) { cerr << "argv1 is invalid." << endl;
cerr << "argv1 is invalid." << endl; exit(-1);
exit(-1); }
} if (stat(fp2.c_str(), &st[1]) == -1) {
if (stat(fp2.c_str(), &st[1]) == -1) { cerr << "argv2 is invalid" << endl;
cerr << "argv2 is invalid" << endl; exit(-1);
exit(-1); }
}
char buf[2][MAX_LENGTH + 1];
char buf[2][MAX_LENGTH + 1]; rawtime[0] = st[0].st_mtime;
rawtime[0] = st[0].st_mtime; timeinfo[0] = localtime(&rawtime[0]);
timeinfo[0] = localtime(&rawtime[0]); strftime(buf[0], MAX_LENGTH, time_format, timeinfo[0]);
strftime(buf[0], MAX_LENGTH, time_format, timeinfo[0]); cout << "--- " << fp1 << '\t' << buf[0] << endl;
cout << "--- " << fp1 << '\t' << buf[0] << endl; rawtime[1] = st[1].st_mtime;
rawtime[1] = st[1].st_mtime; timeinfo[1] = localtime(&rawtime[1]);
timeinfo[1] = localtime(&rawtime[1]); strftime(buf[1], MAX_LENGTH, time_format, timeinfo[1]);
strftime(buf[1], MAX_LENGTH, time_format, timeinfo[1]); cout << "+++ " << fp2 << '\t' << buf[1] << endl;
cout << "+++ " << fp2 << '\t' << buf[1] << endl;
} }
static void unifiedDiff (string fp1, string fp2) static void unifiedDiff(string fp1, string fp2) {
{ typedef string elem;
typedef string elem; typedef vector<elem> sequence;
typedef vector< elem > sequence; typedef pair<elem, elemInfo> sesElem;
typedef pair< elem, elemInfo > sesElem;
ifstream Aifs(fp1.c_str()); ifstream Aifs(fp1.c_str());
ifstream Bifs(fp2.c_str()); ifstream Bifs(fp2.c_str());
elem buf; elem buf;
sequence ALines, BLines; sequence ALines, BLines;
while(getline(Aifs, buf)){ while (getline(Aifs, buf)) {
ALines.push_back(buf); ALines.push_back(buf);
} }
while(getline(Bifs, buf)){ while (getline(Bifs, buf)) {
BLines.push_back(buf); BLines.push_back(buf);
} }
Diff< elem > diff(ALines, BLines); Diff<elem> diff(ALines, BLines);
diff.onHuge(); diff.onHuge();
//diff.onUnserious(); // diff.onUnserious();
diff.compose(); diff.compose();
// type unihunk definition test // type unihunk definition test
uniHunk< sesElem > hunk; uniHunk<sesElem> hunk;
if (diff.getEditDistance() > 0) { if (diff.getEditDistance() > 0) {
showStats(fp1, fp2); // show file info showStats(fp1, fp2); // show file info
} }
diff.composeUnifiedHunks(); diff.composeUnifiedHunks();
diff.printUnifiedFormat(); diff.printUnifiedFormat();
} }
int main(int argc, char *argv[]) {
if (isFewArgs(argc)) {
cerr << "Too few arguments." << endl;
return -1;
}
int main(int argc, char *argv[]) string s1(argv[1]);
{ string s2(argv[2]);
if (isFewArgs(argc)) { bool fileExist = true;
cerr << "Too few arguments." << endl;
return -1; if (!isFileExist(s1)) {
} cerr << s1 << " is invalid." << endl;
fileExist = false;
string s1(argv[1]); }
string s2(argv[2]);
bool fileExist = true; if (!isFileExist(s2)) {
cerr << s2 << " is invalid." << endl;
if (!isFileExist(s1)) { fileExist = false;
cerr << s1 << " is invalid." << endl; }
fileExist = false;
} if (!fileExist) {
return -1;
if (!isFileExist(s2)) { }
cerr << s2 << " is invalid." << endl;
fileExist = false; unifiedDiff(s1, s2);
} return 0;
if (!fileExist) {
return -1;
}
unifiedDiff(s1, s2);
return 0;
} }

View File

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

View File

@ -1,83 +1,80 @@
#include "dtl_test_common.hpp" #include "dtl_test_common.hpp"
class Intdifftest : public ::testing::Test class Intdifftest : public ::testing::Test {
{ protected:
protected : dtl_test_typedefs(int, vector<int>) typedef struct case_t {
dtl_test_typedefs(int, vector< int >) sequence A;
typedef struct case_t { sequence B;
sequence A; size_t editdis;
sequence B; elemVec lcs_v;
size_t editdis; sequence lcs_s;
elemVec lcs_v; sesElemVec ses_seq;
sequence lcs_s; uniHunkVec hunk_v;
sesElemVec ses_seq; size_t editdis_ses;
uniHunkVec hunk_v; size_t editdis_uni;
size_t editdis_ses; string path_rses;
size_t editdis_uni; string path_rhunks;
string path_rses; } case_t;
string path_rhunks; typedef vector<case_t> caseVec;
} case_t; caseVec cases;
typedef vector< case_t > caseVec;
caseVec cases;
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.compose();
diff.composeUnifiedHunks();
if (test_name != "") {
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);
create_file< elem, sequence, Compare< elem > >(path_rses, diff, TYPE_DIFF_SES); case_t createCase(const sequence a, const sequence b, string test_name) {
create_file< elem, sequence, Compare< elem > >(path_rhunks, diff, TYPE_DIFF_UNI); case_t c;
c.editdis_ses = cal_diff_uni(path_lses, path_rses); string diff_name("intdiff");
c.editdis_uni = cal_diff_uni(path_lhunks, path_rhunks); Diff<elem> diff(a, b);
c.path_rses = path_rses; diff.compose();
c.path_rhunks = path_rhunks; diff.composeUnifiedHunks();
}
if (test_name != "") {
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);
c.A = a; create_file<elem, sequence, Compare<elem>>(path_rses, diff,
c.B = b; TYPE_DIFF_SES);
c.editdis = diff.getEditDistance(); create_file<elem, sequence, Compare<elem>>(path_rhunks, diff,
c.lcs_v = diff.getLcsVec(); TYPE_DIFF_UNI);
c.ses_seq = diff.getSes().getSequence(); c.editdis_ses = cal_diff_uni(path_lses, path_rses);
return c; c.editdis_uni = cal_diff_uni(path_lhunks, path_rhunks);
c.path_rses = path_rses;
c.path_rhunks = path_rhunks;
} }
void SetUp() { c.A = a;
cases.push_back(createCase(sequence(0), sequence(0), "diff_test0")); c.B = b;
sequence B1; c.editdis = diff.getEditDistance();
B1.push_back(1); c.lcs_v = diff.getLcsVec();
cases.push_back(createCase(sequence(0), B1, "diff_test1")); c.ses_seq = diff.getSes().getSequence();
sequence A2; return c;
A2.push_back(1); }
cases.push_back(createCase(A2, sequence(0), "diff_test2"));
int a4[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; void SetUp() {
int b4[] = {3, 5, 1, 4, 5, 1, 7, 9, 6, 10}; cases.push_back(createCase(sequence(0), sequence(0), "diff_test0"));
int a4siz = sizeof(a4) / sizeof(int); sequence B1;
int b4siz = sizeof(b4) / sizeof(int); B1.push_back(1);
sequence A4(&a4[0], &a4[a4siz]); cases.push_back(createCase(sequence(0), B1, "diff_test1"));
sequence B4(&b4[0], &b4[b4siz]); sequence A2;
cases.push_back(createCase(A4, B4, "diff_test3")); A2.push_back(1);
int a5[] = {1, 2, 3, 4, 5}; cases.push_back(createCase(A2, sequence(0), "diff_test2"));
int b5[] = {3, 5, 1, 4, 5}; int a4[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int a5siz = sizeof(a5) / sizeof(int); int b4[] = {3, 5, 1, 4, 5, 1, 7, 9, 6, 10};
int b5siz = sizeof(b5) / sizeof(int); int a4siz = sizeof(a4) / sizeof(int);
sequence A5(&a5[0], &a5[a5siz]); int b4siz = sizeof(b4) / sizeof(int);
sequence B5(&b5[0], &b5[b5siz]); sequence A4(&a4[0], &a4[a4siz]);
cases.push_back(createCase(A5, B5, "diff_test4")); sequence B4(&b4[0], &b4[b4siz]);
} cases.push_back(createCase(A4, B4, "diff_test3"));
int a5[] = {1, 2, 3, 4, 5};
void TearDown () { int b5[] = {3, 5, 1, 4, 5};
for_each(cases.begin(), cases.end(), Remover< case_t >()); int a5siz = sizeof(a5) / sizeof(int);
} int b5siz = sizeof(b5) / sizeof(int);
sequence A5(&a5[0], &a5[a5siz]);
sequence B5(&b5[0], &b5[b5siz]);
cases.push_back(createCase(A5, B5, "diff_test4"));
}
void TearDown() { for_each(cases.begin(), cases.end(), Remover<case_t>()); }
}; };
/** /**
@ -87,58 +84,58 @@ protected :
* - LCS * - LCS
* - SES * - SES
*/ */
TEST_F (Intdifftest, diff_test0) { TEST_F(Intdifftest, diff_test0) {
EXPECT_EQ(0, cases[0].editdis); EXPECT_EQ(0, cases[0].editdis);
EXPECT_TRUE(cases[0].lcs_v.empty());
ASSERT_EQ(0, cases[0].editdis_ses);
ASSERT_EQ(0, cases[0].editdis_uni); EXPECT_TRUE(cases[0].lcs_v.empty());
ASSERT_EQ(0, cases[0].editdis_ses);
ASSERT_EQ(0, cases[0].editdis_uni);
} }
TEST_F (Intdifftest, diff_test1) { TEST_F(Intdifftest, diff_test1) {
EXPECT_EQ(1, cases[1].editdis); EXPECT_EQ(1, cases[1].editdis);
EXPECT_TRUE(cases[1].lcs_v.empty());
ASSERT_EQ(0, cases[1].editdis_ses);
ASSERT_EQ(0, cases[1].editdis_uni); EXPECT_TRUE(cases[1].lcs_v.empty());
ASSERT_EQ(0, cases[1].editdis_ses);
ASSERT_EQ(0, cases[1].editdis_uni);
} }
TEST_F (Intdifftest, diff_test2) { TEST_F(Intdifftest, diff_test2) {
EXPECT_EQ(1, cases[2].editdis); EXPECT_EQ(1, cases[2].editdis);
EXPECT_TRUE(cases[2].lcs_v.empty());
ASSERT_EQ(0, cases[2].editdis_ses);
ASSERT_EQ(0, cases[2].editdis_uni); EXPECT_TRUE(cases[2].lcs_v.empty());
ASSERT_EQ(0, cases[2].editdis_ses);
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(8, cases[3].editdis);
EXPECT_EQ(3, cases[3].lcs_v[0]);
EXPECT_EQ(4, cases[3].lcs_v[1]);
EXPECT_EQ(5, cases[3].lcs_v[2]);
EXPECT_EQ(7, cases[3].lcs_v[3]);
EXPECT_EQ(9, cases[3].lcs_v[4]);
ASSERT_EQ(0, cases[3].editdis_ses);
ASSERT_EQ(0, cases[3].editdis_uni); EXPECT_EQ(3, cases[3].lcs_v[0]);
EXPECT_EQ(4, cases[3].lcs_v[1]);
EXPECT_EQ(5, cases[3].lcs_v[2]);
EXPECT_EQ(7, cases[3].lcs_v[3]);
EXPECT_EQ(9, cases[3].lcs_v[4]);
ASSERT_EQ(0, cases[3].editdis_ses);
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(4, cases[4].editdis);
EXPECT_EQ(3, cases[4].lcs_v[0]);
EXPECT_EQ(4, cases[4].lcs_v[1]);
EXPECT_EQ(5, cases[4].lcs_v[2]);
ASSERT_EQ(0, cases[4].editdis_ses);
ASSERT_EQ(0, cases[4].editdis_uni); EXPECT_EQ(3, cases[4].lcs_v[0]);
EXPECT_EQ(4, cases[4].lcs_v[1]);
EXPECT_EQ(5, cases[4].lcs_v[2]);
ASSERT_EQ(0, cases[4].editdis_ses);
ASSERT_EQ(0, cases[4].editdis_uni);
} }

View File

@ -1,116 +1,118 @@
#include "dtl_test_common.hpp"
#include "comparators.hpp" #include "comparators.hpp"
#include "dtl_test_common.hpp"
class Objdifftest : public ::testing::Test class Objdifftest : public ::testing::Test {
{ protected:
protected : dtl_test_typedefs(string, vector<elem>) typedef struct case_t {
dtl_test_typedefs(string, vector<elem>) sequence A;
typedef struct case_t { sequence B;
sequence A; sesElemVec expected;
sequence B; sesElemVec ses_seq;
sesElemVec expected; } case_t;
sesElemVec ses_seq; typedef vector<case_t> caseVec;
} case_t;
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) {
case_t c;
elemVec lcs_v;
string diff_name("objdiff");
Diff< elem, sequence, comparator > diff(a, b, true); caseVec obj_diff_cases;
diff.compose(); template <typename comparator>
case_t createCase(const sequence a, const sequence b, sesElemVec ses,
c.A = a; string test_name) {
c.B = b; case_t c;
c.ses_seq = diff.getSes().getSequence(); elemVec lcs_v;
c.expected = ses; string diff_name("objdiff");
return c; Diff<elem, sequence, comparator> diff(a, b, true);
diff.compose();
c.A = a;
c.B = b;
c.ses_seq = diff.getSes().getSequence();
c.expected = ses;
return c;
}
void SetUp(void) {
{
string array1[] = {"the", "quick", "brown"};
string array2[] = {"The", "Quick", "Fox"};
sequence A(array1, array1 + (sizeof(array1) / sizeof(array1[0])));
sequence B(array2, array2 + (sizeof(array2) / sizeof(array2[0])));
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"));
} }
void SetUp(void) { {
{ string array1[] = {"b", "c", "e", "g"};
string array1[] = {"the", "quick", "brown"}; string array2[] = {"a", "d", "e", "f", "h"};
string array2[] = {"The", "Quick", "Fox"};
sequence A(array1, array1 + (sizeof(array1) / sizeof(array1[0])));
sequence A(array1, array1 + (sizeof(array1) / sizeof(array1[0]))); sequence B(array2, array2 + (sizeof(array2) / sizeof(array2[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("the", 1, 1, dtl::SES_COMMON); ses.addSequence("c", 2, 0, dtl::SES_DELETE);
ses.addSequence("quick", 2, 2, dtl::SES_COMMON); ses.addSequence("a", 0, 1, dtl::SES_ADD);
ses.addSequence("brown", 3, 0, dtl::SES_DELETE); ses.addSequence("d", 0, 2, dtl::SES_ADD);
ses.addSequence("Fox", 0, 3, dtl::SES_ADD); ses.addSequence("e", 3, 3, dtl::SES_COMMON);
ses.addSequence("g", 4, 0, dtl::SES_DELETE);
obj_diff_cases.push_back(createCase< StringCaseInsensitive >(A, B, ses.getSequence(), "objdiff_test0_pattern")); ses.addSequence("f", 0, 4, dtl::SES_ADD);
} ses.addSequence("h", 0, 5, dtl::SES_ADD);
{ obj_diff_cases.push_back(createCase<StringCaseInsensitive>(
string array1[] = {"b", "c", "e", "g"}; A, B, ses.getSequence(), "objdiff_test1_unswapped"));
string array2[] = {"a", "d", "e", "f", "h"};
sequence A(array1, array1 + (sizeof(array1) / sizeof(array1[0])));
sequence B(array2, array2 + (sizeof(array2) / sizeof(array2[0])));
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);
ses.addSequence("d", 0, 2, dtl::SES_ADD);
ses.addSequence("e", 3, 3, dtl::SES_COMMON);
ses.addSequence("g", 4, 0, dtl::SES_DELETE);
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"));
}
{
string array1[] = {"a", "d", "e", "f", "h"};
string array2[] = {"b", "c", "e", "g"};
sequence A(array1, array1 + (sizeof(array1) / sizeof(array1[0])));
sequence B(array2, array2 + (sizeof(array2) / sizeof(array2[0])));
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);
ses.addSequence("c", 0, 2, dtl::SES_ADD);
ses.addSequence("e", 3, 3, dtl::SES_COMMON);
ses.addSequence("f", 4, 0, dtl::SES_DELETE);
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"));
}
} }
{
void TearDown () { string array1[] = {"a", "d", "e", "f", "h"};
//for_each(obj_diff_cases.begin(), obj_diff_cases.end(), Remover< case_t >()); string array2[] = {"b", "c", "e", "g"};
sequence A(array1, array1 + (sizeof(array1) / sizeof(array1[0])));
sequence B(array2, array2 + (sizeof(array2) / sizeof(array2[0])));
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);
ses.addSequence("c", 0, 2, dtl::SES_ADD);
ses.addSequence("e", 3, 3, dtl::SES_COMMON);
ses.addSequence("f", 4, 0, dtl::SES_DELETE);
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"));
} }
}
void TearDown() {
// for_each(obj_diff_cases.begin(), obj_diff_cases.end(), Remover< case_t
// >());
}
}; };
/** /**
* Objdifftest * Objdifftest
* check list: * check list:
* - SES pattern "SES_COMMON, SES_DELETE, SES_ADD" * - SES pattern "SES_COMMON, SES_DELETE, SES_ADD"
* - Indepence of results from swapping * - 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); 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); 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); EXPECT_EQ(obj_diff_cases[2].expected, obj_diff_cases[2].ses_seq);
} }

View File

@ -1,45 +1,98 @@
#include "dtl_test_common.hpp" #include "dtl_test_common.hpp"
class Patchtest : public ::testing::Test class Patchtest : public ::testing::Test {
{ protected:
protected : dtl_test_typedefs(char, string) typedef struct case_t {
dtl_test_typedefs(char, string) sequence A;
typedef struct case_t { sequence B;
sequence A; Diff<elem, sequence> diff;
sequence B; } case_t;
Diff< elem, sequence > diff; typedef vector<case_t> caseVec;
} case_t;
typedef vector< case_t > caseVec; caseVec cases;
caseVec cases; case_t createCase(sequence a, sequence b) {
case_t c;
case_t createCase (sequence a, sequence b) { c.A = a;
case_t c; c.B = b;
c.A = a; c.diff = Diff<elem, sequence>(a, b);
c.B = b; c.diff.compose();
c.diff = Diff< elem, sequence >(a, b); c.diff.composeUnifiedHunks();
c.diff.compose(); return c;
c.diff.composeUnifiedHunks(); }
return c;
} void SetUp() {
cases.push_back(createCase("abc", "abd")); // 0
void SetUp() { cases.push_back(createCase("acbdeacbed", "acebdabbabed")); // 1
cases.push_back(createCase("abc", "abd")); // 0 cases.push_back(createCase("abcdef", "dacfea")); // 2
cases.push_back(createCase("acbdeacbed", "acebdabbabed")); // 1 cases.push_back(createCase("abcbda", "bdcaba")); // 3
cases.push_back(createCase("abcdef", "dacfea")); // 2 cases.push_back(createCase("bokko", "bokkko")); // 4
cases.push_back(createCase("abcbda", "bdcaba")); // 3 cases.push_back(createCase("", "")); // 5
cases.push_back(createCase("bokko", "bokkko")); // 4 cases.push_back(createCase("a", "")); // 6
cases.push_back(createCase("", "")); // 5 cases.push_back(createCase("", "b")); // 7
cases.push_back(createCase("a", "")); // 6 cases.push_back(createCase(
cases.push_back(createCase("", "b")); // 7 "abcdefq3wefarhgorequgho4euhfteowauhfwehogfewrquhoi23hroewhoahfotrhguoi"
cases.push_back(createCase("abcdefq3wefarhgorequgho4euhfteowauhfwehogfewrquhoi23hroewhoahfotrhguoiewahrgqqabcdef", "ewahrgqqabcdef",
"3abcdef4976fd86ouofita67t85r876e5e746578tgliuhopoqqabcdef")); // 8 "3abcdef4976fd86ouofita67t85r876e5e746578tgliuhopoqqabcdef")); // 8
cases.push_back(createCase("abcqqqeqqqccc", "abdqqqeqqqddd")); // 9 cases.push_back(createCase("abcqqqeqqqccc", "abdqqqeqqqddd")); // 9
cases.push_back(createCase("aaaaaaaaaaaaa>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>aaaadsafabcaaaaaaaaaaaaaaaaaaewaaabdaaaaaabbb", "aaaaaaaaaaaaaaadasfdsafsadasdafbaaaaaaaaaaaaaaaaaeaaaaaaaaaae&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&saaabcaaaaaaccc")); // 10 cases.push_back(createCase(
} "aaaaaaaaaaaaa>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
void TearDown () {} ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
"aaaadsafabcaaaaaaaaaaaaaaaaaaewaaabdaaaaaabbb",
"aaaaaaaaaaaaaaadasfdsafsadasdafbaaaaaaaaaaaaaaaaaeaaaaaaaaaae&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&saaabcaaaaaaccc")); // 10
}
void TearDown() {}
}; };
/** /**
@ -48,57 +101,57 @@ protected :
* - patch function * - patch function
* - uniPatch 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.patch(cases[0].A));
ASSERT_EQ(cases[0].B, cases[0].diff.uniPatch(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.patch(cases[1].A));
ASSERT_EQ(cases[1].B, cases[1].diff.uniPatch(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.patch(cases[2].A));
ASSERT_EQ(cases[2].B, cases[2].diff.uniPatch(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.patch(cases[3].A));
ASSERT_EQ(cases[3].B, cases[3].diff.uniPatch(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.patch(cases[4].A));
ASSERT_EQ(cases[4].B, cases[4].diff.uniPatch(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.patch(cases[5].A));
ASSERT_EQ(cases[5].B, cases[5].diff.uniPatch(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.patch(cases[6].A));
ASSERT_EQ(cases[6].B, cases[6].diff.uniPatch(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.patch(cases[7].A));
ASSERT_EQ(cases[7].B, cases[7].diff.uniPatch(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.patch(cases[8].A));
ASSERT_EQ(cases[8].B, cases[8].diff.uniPatch(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.patch(cases[9].A));
ASSERT_EQ(cases[9].B, cases[9].diff.uniPatch(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.patch(cases[10].A));
ASSERT_EQ(cases[10].B, cases[10].diff.uniPatch(cases[10].A)); ASSERT_EQ(cases[10].B, cases[10].diff.uniPatch(cases[10].A));
} }

View File

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

View File

@ -1,71 +1,95 @@
#include "dtl_test_common.hpp"
#include "comparators.hpp" #include "comparators.hpp"
#include "dtl_test_common.hpp"
class Strdiff3test : public ::testing::Test class Strdiff3test : public ::testing::Test {
{ protected:
protected : dtl_test_typedefs(char, string) typedef struct case_t {
dtl_test_typedefs(char, string) sequence S;
typedef struct case_t { bool is_merge_success;
sequence S; sequence merged_seq;
bool is_merge_success; } case_t;
sequence merged_seq; typedef vector<case_t> caseVec;
} case_t;
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);
case_t ct;
diff3.compose(); caseVec merge_cases;
caseVec detect_cases;
caseVec custom_cases;
ct.S = s; template <typename comparator>
ct.is_merge_success = diff3.merge(); case_t createCase(sequence a, sequence b, sequence c, sequence s) {
ct.merged_seq = diff3.getMergedSequence(); Diff3<elem, sequence, comparator> diff3(a, b, c);
return ct; case_t ct;
}
diff3.compose();
void SetUp() {
// merge test ct.S = s;
merge_cases.push_back(createCase< Compare < elem > >("ab", "b", "bc", "abc")); // 0 ct.is_merge_success = diff3.merge();
merge_cases.push_back(createCase< Compare < elem > >("bc", "b", "ab", "abc")); // 1 ct.merged_seq = diff3.getMergedSequence();
merge_cases.push_back(createCase< Compare < elem > >("qqqabc", "abc", "abcdef", "qqqabcdef")); // 2 return ct;
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 void SetUp() {
merge_cases.push_back(createCase< Compare < elem > >("aeaacccbbb", "aaabbb", "aaabbbqqq", "aeaacccbbbqqq")); // 6 // merge test
merge_cases.push_back(createCase< Compare < elem > >("aaabbbqqq", "aaabbb", "aeaacccbbb", "aeaacccbbbqqq")); // 7 merge_cases.push_back(
merge_cases.push_back(createCase< Compare < elem > >("aeaacccbbb", "aaabbb", "aaabebbqqq", "aeaacccbebbqqq")); // 8 createCase<Compare<elem>>("ab", "b", "bc", "abc")); // 0
merge_cases.push_back(createCase< Compare < elem > >("aaabebbqqq", "aaabbb", "aeaacccbbb", "aeaacccbebbqqq")); // 9 merge_cases.push_back(
merge_cases.push_back(createCase< Compare < elem > >("aaacccbbb", "aaabbb", "aeaabbbqqq", "aeaacccbbbqqq")); // 10 createCase<Compare<elem>>("bc", "b", "ab", "abc")); // 1
merge_cases.push_back(createCase< Compare < elem > >("aeaabbbqqq", "aaabbb", "aaacccbbb", "aeaacccbbbqqq")); // 11 merge_cases.push_back(
merge_cases.push_back(createCase< Compare < elem > >("aaacccbbb", "aaabbb", "aaabeebbeeqqq","aaacccbeebbeeqqq")); // 12 createCase<Compare<elem>>("qqqabc", "abc", "abcdef", "qqqabcdef")); // 2
merge_cases.push_back(createCase< Compare < elem > >("aaabeebbeeqqq", "aaabbb", "aaacccbbb", "aaacccbeebbeeqqq")); // 13 merge_cases.push_back(
merge_cases.push_back(createCase< Compare < elem > >("aiueo", "aeo", "aeKokaki", "aiueKokaki")); // 14 createCase<Compare<elem>>("abcdef", "abc", "qqqabc", "qqqabcdef")); // 3
merge_cases.push_back(createCase< Compare < elem > >("aeKokaki", "aeo", "aiueo", "aiueKokaki")); // 15 merge_cases.push_back(createCase<Compare<elem>>(
merge_cases.push_back(createCase< Compare < elem > >("1234567390", "1234567890", "1239567890", "1239567390")); // 16 "aaacccbbb", "aaabbb", "aaabbbqqq", "aaacccbbbqqq")); // 4
merge_cases.push_back(createCase< Compare < elem > >("1239567890", "1234567890", "1234567390", "1239567390")); // 17 merge_cases.push_back(createCase<Compare<elem>>(
merge_cases.push_back(createCase< Compare < elem > >("qabcdef", "abcdef", "ab", "qab")); // 18 "aaabbbqqq", "aaabbb", "aaacccbbb", "aaacccbbbqqq")); // 5
merge_cases.push_back(createCase< Compare < elem > >("ab", "abcdef", "qabcdef", "qab")); // 19 merge_cases.push_back(createCase<Compare<elem>>(
merge_cases.push_back(createCase< Compare < elem > >("abcdf", "abcdef", "acdef", "acdf")); // 20 "aeaacccbbb", "aaabbb", "aaabbbqqq", "aeaacccbbbqqq")); // 6
merge_cases.push_back(createCase< Compare < elem > >("acdef", "abcdef", "abcdf", "acdf")); // 21 merge_cases.push_back(createCase<Compare<elem>>(
merge_cases.push_back(createCase< Compare < elem > >("acdef", "abcdef", "abcdfaa", "acdfaa")); // 22 "aaabbbqqq", "aaabbb", "aeaacccbbb", "aeaacccbbbqqq")); // 7
merge_cases.push_back(createCase< Compare < elem > >("abcdfaa", "abcdef", "acdef", "acdfaa")); // 23 merge_cases.push_back(createCase<Compare<elem>>(
"aeaacccbbb", "aaabbb", "aaabebbqqq", "aeaacccbebbqqq")); // 8
// detect confliction test merge_cases.push_back(createCase<Compare<elem>>(
detect_cases.push_back(createCase< Compare < elem > >("adc", "abc", "aec", "")); // 0 "aaabebbqqq", "aaabbb", "aeaacccbbb", "aeaacccbebbqqq")); // 9
detect_cases.push_back(createCase< Compare < elem > >("abqdcf", "abcdef", "abqqef", "")); // 1 merge_cases.push_back(createCase<Compare<elem>>(
"aaacccbbb", "aaabbb", "aeaabbbqqq", "aeaacccbbbqqq")); // 10
// use custom comparator merge_cases.push_back(createCase<Compare<elem>>(
custom_cases.push_back(createCase< CaseInsensitive >("abc", "abc", "abC", "abc")); "aeaabbbqqq", "aaabbb", "aaacccbbb", "aeaacccbbbqqq")); // 11
} merge_cases.push_back(createCase<Compare<elem>>(
"aaacccbbb", "aaabbb", "aaabeebbeeqqq", "aaacccbeebbeeqqq")); // 12
void TearDown () {} 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
// use custom comparator
custom_cases.push_back(
createCase<CaseInsensitive>("abc", "abc", "abC", "abc"));
}
void TearDown() {}
}; };
/** /**
@ -74,135 +98,135 @@ protected :
* - merge function * - merge function
* - detect confliction * - detect confliction
*/ */
TEST_F (Strdiff3test, merge_test0) { TEST_F(Strdiff3test, merge_test0) {
ASSERT_TRUE(merge_cases[0].is_merge_success); ASSERT_TRUE(merge_cases[0].is_merge_success);
ASSERT_EQ(merge_cases[0].S, merge_cases[0].merged_seq); 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_TRUE(merge_cases[1].is_merge_success);
ASSERT_EQ(merge_cases[1].S, merge_cases[1].merged_seq); 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_TRUE(merge_cases[2].is_merge_success);
ASSERT_EQ(merge_cases[2].S, merge_cases[2].merged_seq); 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_TRUE(merge_cases[3].is_merge_success);
ASSERT_EQ(merge_cases[3].S, merge_cases[3].merged_seq); 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_TRUE(merge_cases[4].is_merge_success);
ASSERT_EQ(merge_cases[4].S, merge_cases[4].merged_seq); 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_TRUE(merge_cases[5].is_merge_success);
ASSERT_EQ(merge_cases[5].S, merge_cases[5].merged_seq); 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_TRUE(merge_cases[6].is_merge_success);
ASSERT_EQ(merge_cases[6].S, merge_cases[6].merged_seq); 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_TRUE(merge_cases[7].is_merge_success);
ASSERT_EQ(merge_cases[7].S, merge_cases[7].merged_seq); 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_TRUE(merge_cases[8].is_merge_success);
ASSERT_EQ(merge_cases[8].S, merge_cases[8].merged_seq); 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_TRUE(merge_cases[9].is_merge_success);
ASSERT_EQ(merge_cases[9].S, merge_cases[9].merged_seq); 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_TRUE(merge_cases[10].is_merge_success);
ASSERT_EQ(merge_cases[10].S, merge_cases[10].merged_seq); 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_TRUE(merge_cases[11].is_merge_success);
ASSERT_EQ(merge_cases[11].S, merge_cases[11].merged_seq); 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_TRUE(merge_cases[12].is_merge_success);
ASSERT_EQ(merge_cases[12].S, merge_cases[12].merged_seq); 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_TRUE(merge_cases[13].is_merge_success);
ASSERT_EQ(merge_cases[13].S, merge_cases[13].merged_seq); 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_TRUE(merge_cases[14].is_merge_success);
ASSERT_EQ(merge_cases[14].S, merge_cases[14].merged_seq); 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_TRUE(merge_cases[15].is_merge_success);
ASSERT_EQ(merge_cases[15].S, merge_cases[15].merged_seq); 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_TRUE(merge_cases[16].is_merge_success);
ASSERT_EQ(merge_cases[16].S, merge_cases[16].merged_seq); 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_TRUE(merge_cases[17].is_merge_success);
ASSERT_EQ(merge_cases[17].S, merge_cases[17].merged_seq); 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_TRUE(merge_cases[18].is_merge_success);
ASSERT_EQ(merge_cases[18].S, merge_cases[18].merged_seq); 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_TRUE(merge_cases[19].is_merge_success);
ASSERT_EQ(merge_cases[19].S, merge_cases[19].merged_seq); 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_TRUE(merge_cases[20].is_merge_success);
ASSERT_EQ(merge_cases[20].S, merge_cases[20].merged_seq); 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_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_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_TRUE(merge_cases[23].is_merge_success);
ASSERT_EQ(merge_cases[23].S, merge_cases[23].merged_seq); 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); 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); 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_TRUE(custom_cases[0].is_merge_success);
ASSERT_EQ(custom_cases[0].S, custom_cases[0].merged_seq); ASSERT_EQ(custom_cases[0].S, custom_cases[0].merged_seq);
} }

View File

@ -1,102 +1,113 @@
#include "dtl_test_common.hpp"
#include "comparators.hpp" #include "comparators.hpp"
#include "dtl_test_common.hpp"
class Strdifftest : public ::testing::Test class Strdifftest : public ::testing::Test {
{ protected:
protected : dtl_test_typedefs(char, string) typedef struct case_t {
dtl_test_typedefs(char, string) sequence A;
typedef struct case_t { sequence B;
sequence A; size_t editdis;
sequence B; elemVec lcs_v;
size_t editdis; sequence lcs_s;
elemVec lcs_v; sesElemVec ses_seq;
sequence lcs_s; uniHunkVec hunk_v;
sesElemVec ses_seq; size_t editdis_ses;
uniHunkVec hunk_v; size_t editdis_uni;
size_t editdis_ses; string path_rses;
size_t editdis_uni; string path_rhunks;
string path_rses; } case_t;
string path_rhunks; typedef vector<case_t> caseVec;
} case_t;
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) {
case_t c;
elemVec lcs_v;
string diff_name("strdiff");
Diff< elem, sequence, comparator > diff(a, b); caseVec diff_cases;
if (onlyEditdis) { caseVec only_editdis_cases;
diff.onOnlyEditDistance(); caseVec custom_cases;
}
diff.compose(); template <typename comparator>
diff.composeUnifiedHunks(); case_t createCase(const sequence a, const sequence b, string test_name,
lcs_v = diff.getLcsVec(); bool onlyEditdis = false) {
case_t c;
if (test_name != "") { elemVec lcs_v;
string path_lses = create_path(test_name, diff_name, TYPE_DIFF_SES); string diff_name("strdiff");
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);
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);
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; Diff<elem, sequence, comparator> diff(a, b);
c.B = b; if (onlyEditdis) {
c.editdis = diff.getEditDistance(); diff.onOnlyEditDistance();
c.lcs_s = sequence(lcs_v.begin(), lcs_v.end());
c.ses_seq = diff.getSes().getSequence();
c.hunk_v = diff.getUniHunks();
return c;
} }
void SetUp(void) { diff.compose();
diff_cases.push_back(createCase< Compare< elem > >("abc", "abd", "diff_test0")); diff.composeUnifiedHunks();
diff_cases.push_back(createCase< Compare< elem > >("acbdeacbed", "acebdabbabed", "diff_test1")); lcs_v = diff.getLcsVec();
diff_cases.push_back(createCase< Compare< elem > >("abcdef", "dacfea", "diff_test2"));
diff_cases.push_back(createCase< Compare< elem > >("abcbda", "bdcaba", "diff_test3")); if (test_name != "") {
diff_cases.push_back(createCase< Compare< elem > >("bokko", "bokkko", "diff_test4")); string path_lses = create_path(test_name, diff_name, TYPE_DIFF_SES);
diff_cases.push_back(createCase< Compare< elem > >("", "", "diff_test5")); string path_rses = create_path(test_name, diff_name, TYPE_DIFF_SES, true);
diff_cases.push_back(createCase< Compare< elem > >("a", "", "diff_test6")); string path_lhunks = create_path(test_name, diff_name, TYPE_DIFF_UNI);
diff_cases.push_back(createCase< Compare< elem > >("", "b", "diff_test7")); string path_rhunks =
diff_cases.push_back(createCase< Compare< elem > >("acbdeaqqqqqqqcbed", "acebdabbqqqqqqqabed", "diff_test8")); create_path(test_name, diff_name, TYPE_DIFF_UNI, true);
diff_resultset_exist_check(path_lses);
only_editdis_cases.push_back(createCase< Compare< elem > >("abc", "abd", "", true)); diff_resultset_exist_check(path_lhunks);
only_editdis_cases.push_back(createCase< Compare< elem > >("acbdeacbed", "acebdabbabed", "", true));
only_editdis_cases.push_back(createCase< Compare< elem > >("abcdef", "dacfea", "", true)); create_file<elem, sequence, comparator>(path_rses, diff, TYPE_DIFF_SES);
only_editdis_cases.push_back(createCase< Compare< elem > >("abcbda", "bdcaba", "", true)); create_file<elem, sequence, comparator>(path_rhunks, diff, TYPE_DIFF_UNI);
only_editdis_cases.push_back(createCase< Compare< elem > >("bokko", "bokkko", "", true));
only_editdis_cases.push_back(createCase< Compare< elem > >("", "", "", true)); c.editdis_ses = cal_diff_uni(path_lses, path_rses);
only_editdis_cases.push_back(createCase< Compare< elem > >("a", "", "", true)); c.editdis_uni = cal_diff_uni(path_lhunks, path_rhunks);
only_editdis_cases.push_back(createCase< Compare< elem > >("", "b", "", true)); c.path_rses = path_rses;
only_editdis_cases.push_back(createCase< Compare< elem > >("acbdeaqqqqqqqcbed", "acebdabbqqqqqqqabed", "", true)); c.path_rhunks = path_rhunks;
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 >());
} }
c.A = a;
c.B = b;
c.editdis = diff.getEditDistance();
c.lcs_s = sequence(lcs_v.begin(), lcs_v.end());
c.ses_seq = diff.getSes().getSequence();
c.hunk_v = diff.getUniHunks();
return c;
}
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"));
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"));
}
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 * Strdifftest
* check list is following * check list is following
@ -107,193 +118,193 @@ protected :
* - onOnlyEditDistance * - onOnlyEditDistance
*/ */
TEST_F (Strdifftest, diff_test0) { TEST_F(Strdifftest, diff_test0) {
EXPECT_EQ(2, diff_cases[0].editdis);
EXPECT_EQ("ab", diff_cases[0].lcs_s);
ASSERT_EQ(0, diff_cases[0].editdis_ses);
ASSERT_EQ(0, diff_cases[0].editdis_uni); EXPECT_EQ(2, diff_cases[0].editdis);
EXPECT_EQ("ab", diff_cases[0].lcs_s);
ASSERT_EQ(0, diff_cases[0].editdis_ses);
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(6, diff_cases[1].editdis);
EXPECT_EQ("acbdabed", diff_cases[1].lcs_s); EXPECT_EQ("acbdabed", diff_cases[1].lcs_s);
ASSERT_EQ(0, diff_cases[1].editdis_ses); ASSERT_EQ(0, diff_cases[1].editdis_ses);
ASSERT_EQ(0, diff_cases[1].editdis_uni); 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(6, diff_cases[2].editdis);
EXPECT_EQ("acf", diff_cases[2].lcs_s); EXPECT_EQ("acf", diff_cases[2].lcs_s);
ASSERT_EQ(0, diff_cases[2].editdis_ses); ASSERT_EQ(0, diff_cases[2].editdis_ses);
ASSERT_EQ(0, diff_cases[2].editdis_uni); 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(4, diff_cases[3].editdis);
EXPECT_EQ("bcba", diff_cases[3].lcs_s); EXPECT_EQ("bcba", diff_cases[3].lcs_s);
ASSERT_EQ(0, diff_cases[3].editdis_ses); ASSERT_EQ(0, diff_cases[3].editdis_ses);
ASSERT_EQ(0, diff_cases[3].editdis_uni); 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(1, diff_cases[4].editdis);
EXPECT_EQ("bokko", diff_cases[4].lcs_s); EXPECT_EQ("bokko", diff_cases[4].lcs_s);
ASSERT_EQ(0, diff_cases[4].editdis_ses); ASSERT_EQ(0, diff_cases[4].editdis_ses);
ASSERT_EQ(0, diff_cases[4].editdis_uni); 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(0, diff_cases[5].editdis);
EXPECT_EQ("", diff_cases[5].lcs_s); EXPECT_EQ("", diff_cases[5].lcs_s);
ASSERT_EQ(0, diff_cases[5].editdis_ses); ASSERT_EQ(0, diff_cases[5].editdis_ses);
ASSERT_EQ(0, diff_cases[5].editdis_uni); 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(1, diff_cases[6].editdis);
EXPECT_EQ("", diff_cases[6].lcs_s); EXPECT_EQ("", diff_cases[6].lcs_s);
ASSERT_EQ(0, diff_cases[6].editdis_ses); ASSERT_EQ(0, diff_cases[6].editdis_ses);
ASSERT_EQ(0, diff_cases[6].editdis_uni); 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(1, diff_cases[7].editdis);
EXPECT_EQ("", diff_cases[7].lcs_s); EXPECT_EQ("", diff_cases[7].lcs_s);
ASSERT_EQ(0, diff_cases[7].editdis_ses); ASSERT_EQ(0, diff_cases[7].editdis_ses);
ASSERT_EQ(0, diff_cases[7].editdis_uni); 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(6, diff_cases[8].editdis);
EXPECT_EQ("acbdaqqqqqqqbed", diff_cases[8].lcs_s);
ASSERT_EQ(0, diff_cases[8].editdis_ses);
ASSERT_EQ(0, diff_cases[8].editdis_uni); EXPECT_EQ("acbdaqqqqqqqbed", diff_cases[8].lcs_s);
ASSERT_EQ(0, diff_cases[8].editdis_ses);
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(2, only_editdis_cases[0].editdis);
EXPECT_EQ("", only_editdis_cases[0].lcs_s); EXPECT_EQ("", only_editdis_cases[0].lcs_s);
ASSERT_TRUE(only_editdis_cases[0].ses_seq.empty()); ASSERT_TRUE(only_editdis_cases[0].ses_seq.empty());
ASSERT_TRUE(only_editdis_cases[0].hunk_v.empty()); 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(6, only_editdis_cases[1].editdis);
EXPECT_EQ("", only_editdis_cases[1].lcs_s); EXPECT_EQ("", only_editdis_cases[1].lcs_s);
ASSERT_TRUE(only_editdis_cases[1].ses_seq.empty()); ASSERT_TRUE(only_editdis_cases[1].ses_seq.empty());
ASSERT_TRUE(only_editdis_cases[1].hunk_v.empty()); 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(6, only_editdis_cases[2].editdis);
EXPECT_EQ("", only_editdis_cases[2].lcs_s); EXPECT_EQ("", only_editdis_cases[2].lcs_s);
ASSERT_TRUE(only_editdis_cases[2].ses_seq.empty()); ASSERT_TRUE(only_editdis_cases[2].ses_seq.empty());
ASSERT_TRUE(only_editdis_cases[2].hunk_v.empty()); 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(4, only_editdis_cases[3].editdis);
EXPECT_EQ("", only_editdis_cases[3].lcs_s); EXPECT_EQ("", only_editdis_cases[3].lcs_s);
ASSERT_TRUE(only_editdis_cases[3].ses_seq.empty()); ASSERT_TRUE(only_editdis_cases[3].ses_seq.empty());
ASSERT_TRUE(only_editdis_cases[3].hunk_v.empty()); 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(1, only_editdis_cases[4].editdis);
EXPECT_EQ("", only_editdis_cases[4].lcs_s); EXPECT_EQ("", only_editdis_cases[4].lcs_s);
ASSERT_TRUE(only_editdis_cases[4].ses_seq.empty()); ASSERT_TRUE(only_editdis_cases[4].ses_seq.empty());
ASSERT_TRUE(only_editdis_cases[4].hunk_v.empty()); 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(0, only_editdis_cases[5].editdis);
EXPECT_EQ("", only_editdis_cases[5].lcs_s); EXPECT_EQ("", only_editdis_cases[5].lcs_s);
ASSERT_TRUE(only_editdis_cases[5].ses_seq.empty()); ASSERT_TRUE(only_editdis_cases[5].ses_seq.empty());
ASSERT_TRUE(only_editdis_cases[5].hunk_v.empty()); 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(1, only_editdis_cases[6].editdis);
EXPECT_EQ("", only_editdis_cases[6].lcs_s); EXPECT_EQ("", only_editdis_cases[6].lcs_s);
ASSERT_TRUE(only_editdis_cases[6].ses_seq.empty()); ASSERT_TRUE(only_editdis_cases[6].ses_seq.empty());
ASSERT_TRUE(only_editdis_cases[6].hunk_v.empty()); 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(1, only_editdis_cases[7].editdis);
EXPECT_EQ("", only_editdis_cases[7].lcs_s); EXPECT_EQ("", only_editdis_cases[7].lcs_s);
ASSERT_TRUE(only_editdis_cases[7].ses_seq.empty()); ASSERT_TRUE(only_editdis_cases[7].ses_seq.empty());
ASSERT_TRUE(only_editdis_cases[7].hunk_v.empty()); 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(6, only_editdis_cases[8].editdis);
EXPECT_EQ("", only_editdis_cases[8].lcs_s); EXPECT_EQ("", only_editdis_cases[8].lcs_s);
ASSERT_TRUE(only_editdis_cases[8].ses_seq.empty()); ASSERT_TRUE(only_editdis_cases[8].ses_seq.empty());
ASSERT_TRUE(only_editdis_cases[8].hunk_v.empty()); 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(0, custom_cases[0].editdis);
EXPECT_EQ("abc", custom_cases[0].lcs_s);
ASSERT_EQ(0, custom_cases[0].editdis_ses); EXPECT_EQ("abc", custom_cases[0].lcs_s);
ASSERT_TRUE(custom_cases[0].hunk_v.empty()); ASSERT_EQ(0, custom_cases[0].editdis_ses);
ASSERT_TRUE(custom_cases[0].hunk_v.empty());
} }

View File

@ -1,24 +1,23 @@
#ifndef DTL_COMPARATORS #ifndef DTL_COMPARATORS
#define DTL_COMPARATORS #define DTL_COMPARATORS
class CaseInsensitive: public dtl::Compare<char> { class CaseInsensitive : public dtl::Compare<char> {
public: 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); return tolower(a) == tolower(b);
} }
}; };
class StringCaseInsensitive: public dtl::Compare<string> { class StringCaseInsensitive : public dtl::Compare<string> {
public: 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()) { if (a.length() == b.length()) {
bool equal = (strncasecmp(a.c_str(), b.c_str(), a.length()) == 0); bool equal = (strncasecmp(a.c_str(), b.c_str(), a.length()) == 0);
return equal; return equal;
} } else {
else { return false;
return false;
}
} }
}
}; };
#endif // DTL_COMPARATORS #endif // DTL_COMPARATORS

View File

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

View File

@ -1,56 +1,63 @@
#include "dtl_test_common.hpp" #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,
string ret; bool is_use_suffix) {
switch (t) { string ret;
case TYPE_DIFF_SES: switch (t) {
ret = (getcwd(NULL, 0) + string("/") + string("ses") + string("/") + diff_name + string("/") + test_name); case TYPE_DIFF_SES:
break; ret = (getcwd(NULL, 0) + string("/") + string("ses") + string("/") +
case TYPE_DIFF_UNI: diff_name + string("/") + test_name);
ret = (getcwd(NULL, 0) + string("/") + string("hunks") + string("/") + diff_name + string("/") + test_name); break;
break; case TYPE_DIFF_UNI:
} ret = (getcwd(NULL, 0) + string("/") + string("hunks") + string("/") +
ret += is_use_suffix ? "_" : ""; diff_name + string("/") + test_name);
return ret; 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; string buf;
ifstream lifs(path_l.c_str()); ifstream lifs(path_l.c_str());
ifstream rifs(path_r.c_str()); ifstream rifs(path_r.c_str());
vector< string > llines; vector<string> llines;
vector< string > rlines; vector<string> rlines;
while (getline(lifs, buf)) { while (getline(lifs, buf)) {
llines.push_back(buf); llines.push_back(buf);
} }
while (getline(rifs, buf)) {
rlines.push_back(buf);
}
Diff< string, vector< string > > diff_uni(llines, rlines); while (getline(rifs, buf)) {
diff_uni.compose(); rlines.push_back(buf);
return diff_uni.getEditDistance(); }
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; FILE *fp;
if ((fp = fopen(fs.c_str(), "r")) == NULL) { if ((fp = fopen(fs.c_str(), "r")) == NULL) {
return false; return false;
} }
fclose(fp); fclose(fp);
return true; return true;
} }
void diff_resultset_exist_check (string &fs) { void diff_resultset_exist_check(string &fs) {
if (!is_file_exist(fs)) { if (!is_file_exist(fs)) {
cerr << "======================================================Error!!!======================================================" << endl; cerr << "======================================================Error!!!===="
cerr << "diff result set:" << fs << " is not found." << endl; "=================================================="
cerr << "======================================================Error!!!======================================================" << endl; << endl;
cerr << "excute dtl_test in dtl/test!" << endl; cerr << "diff result set:" << fs << " is not found." << endl;
exit(EXIT_FAILURE); cerr << "======================================================Error!!!===="
} "=================================================="
<< endl;
cerr << "excute dtl_test in dtl/test!" << endl;
exit(EXIT_FAILURE);
}
} }

View File

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