Skip to content

Commit 1a075f3

Browse files
committed
Adds tests for LCS
1 parent 308d8e0 commit 1a075f3

File tree

4 files changed

+403
-0
lines changed

4 files changed

+403
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Foundation
2+
import XCTest
3+
4+
class LongestCommonSubsquenceTests: XCTestCase {
5+
6+
func testLCSwithSelfIsSelf() {
7+
let a = "ABCDE"
8+
9+
XCTAssertEqual(a, a.longestCommonSubsequence(a))
10+
}
11+
12+
func testLCSWithEmptyStringIsEmptyString() {
13+
let a = "ABCDE"
14+
15+
XCTAssertEqual("", a.longestCommonSubsequence(""))
16+
}
17+
18+
func testLCSIsEmptyWhenNoCharMatches() {
19+
let a = "ABCDE"
20+
let b = "WXYZ"
21+
22+
XCTAssertEqual("", a.longestCommonSubsequence(b))
23+
}
24+
25+
func testLCSIsNotCommutative() {
26+
let a = "ABCDEF"
27+
let b = "XAWDMVBEKD"
28+
29+
XCTAssertEqual("ADE", a.longestCommonSubsequence(b))
30+
XCTAssertEqual("ABD", b.longestCommonSubsequence(a))
31+
}
32+
}
Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
// !$*UTF8*$!
2+
{
3+
archiveVersion = 1;
4+
classes = {
5+
};
6+
objectVersion = 46;
7+
objects = {
8+
9+
/* Begin PBXBuildFile section */
10+
4716C7AF1C93751E00F6C1C0 /* LongestCommonSubsquenceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4716C7891C936E0E00F6C1C0 /* LongestCommonSubsquenceTests.swift */; };
11+
4716C7B01C93751E00F6C1C0 /* LongestCommonSubsequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4716C7881C936DDD00F6C1C0 /* LongestCommonSubsequence.swift */; };
12+
/* End PBXBuildFile section */
13+
14+
/* Begin PBXFileReference section */
15+
4716C7881C936DDD00F6C1C0 /* LongestCommonSubsequence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = LongestCommonSubsequence.swift; path = ../../LongestCommonSubsequence.swift; sourceTree = "<group>"; };
16+
4716C7891C936E0E00F6C1C0 /* LongestCommonSubsquenceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = LongestCommonSubsquenceTests.swift; path = ../LongestCommonSubsquenceTests.swift; sourceTree = "<group>"; };
17+
4716C7A71C93750500F6C1C0 /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
18+
4716C7AB1C93750500F6C1C0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
19+
/* End PBXFileReference section */
20+
21+
/* Begin PBXFrameworksBuildPhase section */
22+
4716C7A41C93750500F6C1C0 /* Frameworks */ = {
23+
isa = PBXFrameworksBuildPhase;
24+
buildActionMask = 2147483647;
25+
files = (
26+
);
27+
runOnlyForDeploymentPostprocessing = 0;
28+
};
29+
/* End PBXFrameworksBuildPhase section */
30+
31+
/* Begin PBXGroup section */
32+
4716C7811C936DCB00F6C1C0 = {
33+
isa = PBXGroup;
34+
children = (
35+
4716C7A81C93750500F6C1C0 /* Tests */,
36+
4716C78F1C93746D00F6C1C0 /* Products */,
37+
);
38+
sourceTree = "<group>";
39+
};
40+
4716C78F1C93746D00F6C1C0 /* Products */ = {
41+
isa = PBXGroup;
42+
children = (
43+
4716C7A71C93750500F6C1C0 /* Tests.xctest */,
44+
);
45+
name = Products;
46+
sourceTree = "<group>";
47+
};
48+
4716C7A81C93750500F6C1C0 /* Tests */ = {
49+
isa = PBXGroup;
50+
children = (
51+
4716C7891C936E0E00F6C1C0 /* LongestCommonSubsquenceTests.swift */,
52+
4716C7881C936DDD00F6C1C0 /* LongestCommonSubsequence.swift */,
53+
4716C7AB1C93750500F6C1C0 /* Info.plist */,
54+
);
55+
path = Tests;
56+
sourceTree = "<group>";
57+
};
58+
/* End PBXGroup section */
59+
60+
/* Begin PBXNativeTarget section */
61+
4716C7A61C93750500F6C1C0 /* Tests */ = {
62+
isa = PBXNativeTarget;
63+
buildConfigurationList = 4716C7AC1C93750500F6C1C0 /* Build configuration list for PBXNativeTarget "Tests" */;
64+
buildPhases = (
65+
4716C7A31C93750500F6C1C0 /* Sources */,
66+
4716C7A41C93750500F6C1C0 /* Frameworks */,
67+
4716C7A51C93750500F6C1C0 /* Resources */,
68+
);
69+
buildRules = (
70+
);
71+
dependencies = (
72+
);
73+
name = Tests;
74+
productName = Tests;
75+
productReference = 4716C7A71C93750500F6C1C0 /* Tests.xctest */;
76+
productType = "com.apple.product-type.bundle.unit-test";
77+
};
78+
/* End PBXNativeTarget section */
79+
80+
/* Begin PBXProject section */
81+
4716C7821C936DCB00F6C1C0 /* Project object */ = {
82+
isa = PBXProject;
83+
attributes = {
84+
LastSwiftUpdateCheck = 0720;
85+
LastUpgradeCheck = 0720;
86+
TargetAttributes = {
87+
4716C7A61C93750500F6C1C0 = {
88+
CreatedOnToolsVersion = 7.2.1;
89+
};
90+
};
91+
};
92+
buildConfigurationList = 4716C7851C936DCB00F6C1C0 /* Build configuration list for PBXProject "Tests" */;
93+
compatibilityVersion = "Xcode 3.2";
94+
developmentRegion = English;
95+
hasScannedForEncodings = 0;
96+
knownRegions = (
97+
en,
98+
);
99+
mainGroup = 4716C7811C936DCB00F6C1C0;
100+
productRefGroup = 4716C78F1C93746D00F6C1C0 /* Products */;
101+
projectDirPath = "";
102+
projectRoot = "";
103+
targets = (
104+
4716C7A61C93750500F6C1C0 /* Tests */,
105+
);
106+
};
107+
/* End PBXProject section */
108+
109+
/* Begin PBXResourcesBuildPhase section */
110+
4716C7A51C93750500F6C1C0 /* Resources */ = {
111+
isa = PBXResourcesBuildPhase;
112+
buildActionMask = 2147483647;
113+
files = (
114+
);
115+
runOnlyForDeploymentPostprocessing = 0;
116+
};
117+
/* End PBXResourcesBuildPhase section */
118+
119+
/* Begin PBXSourcesBuildPhase section */
120+
4716C7A31C93750500F6C1C0 /* Sources */ = {
121+
isa = PBXSourcesBuildPhase;
122+
buildActionMask = 2147483647;
123+
files = (
124+
4716C7AF1C93751E00F6C1C0 /* LongestCommonSubsquenceTests.swift in Sources */,
125+
4716C7B01C93751E00F6C1C0 /* LongestCommonSubsequence.swift in Sources */,
126+
);
127+
runOnlyForDeploymentPostprocessing = 0;
128+
};
129+
/* End PBXSourcesBuildPhase section */
130+
131+
/* Begin XCBuildConfiguration section */
132+
4716C7861C936DCB00F6C1C0 /* Debug */ = {
133+
isa = XCBuildConfiguration;
134+
buildSettings = {
135+
};
136+
name = Debug;
137+
};
138+
4716C7871C936DCB00F6C1C0 /* Release */ = {
139+
isa = XCBuildConfiguration;
140+
buildSettings = {
141+
};
142+
name = Release;
143+
};
144+
4716C7AD1C93750500F6C1C0 /* Debug */ = {
145+
isa = XCBuildConfiguration;
146+
buildSettings = {
147+
ALWAYS_SEARCH_USER_PATHS = NO;
148+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
149+
CLANG_CXX_LIBRARY = "libc++";
150+
CLANG_ENABLE_MODULES = YES;
151+
CLANG_ENABLE_OBJC_ARC = YES;
152+
CLANG_WARN_BOOL_CONVERSION = YES;
153+
CLANG_WARN_CONSTANT_CONVERSION = YES;
154+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
155+
CLANG_WARN_EMPTY_BODY = YES;
156+
CLANG_WARN_ENUM_CONVERSION = YES;
157+
CLANG_WARN_INT_CONVERSION = YES;
158+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
159+
CLANG_WARN_UNREACHABLE_CODE = YES;
160+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
161+
CODE_SIGN_IDENTITY = "-";
162+
COMBINE_HIDPI_IMAGES = YES;
163+
COPY_PHASE_STRIP = NO;
164+
DEBUG_INFORMATION_FORMAT = dwarf;
165+
ENABLE_STRICT_OBJC_MSGSEND = YES;
166+
ENABLE_TESTABILITY = YES;
167+
GCC_C_LANGUAGE_STANDARD = gnu99;
168+
GCC_DYNAMIC_NO_PIC = NO;
169+
GCC_NO_COMMON_BLOCKS = YES;
170+
GCC_OPTIMIZATION_LEVEL = 0;
171+
GCC_PREPROCESSOR_DEFINITIONS = (
172+
"DEBUG=1",
173+
"$(inherited)",
174+
);
175+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
176+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
177+
GCC_WARN_UNDECLARED_SELECTOR = YES;
178+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
179+
GCC_WARN_UNUSED_FUNCTION = YES;
180+
GCC_WARN_UNUSED_VARIABLE = YES;
181+
INFOPLIST_FILE = Tests/Info.plist;
182+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
183+
MACOSX_DEPLOYMENT_TARGET = 10.10;
184+
MTL_ENABLE_DEBUG_INFO = YES;
185+
ONLY_ACTIVE_ARCH = YES;
186+
PRODUCT_BUNDLE_IDENTIFIER = me.pedrovereza.Tests;
187+
PRODUCT_NAME = "$(TARGET_NAME)";
188+
SDKROOT = macosx;
189+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
190+
};
191+
name = Debug;
192+
};
193+
4716C7AE1C93750500F6C1C0 /* Release */ = {
194+
isa = XCBuildConfiguration;
195+
buildSettings = {
196+
ALWAYS_SEARCH_USER_PATHS = NO;
197+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
198+
CLANG_CXX_LIBRARY = "libc++";
199+
CLANG_ENABLE_MODULES = YES;
200+
CLANG_ENABLE_OBJC_ARC = YES;
201+
CLANG_WARN_BOOL_CONVERSION = YES;
202+
CLANG_WARN_CONSTANT_CONVERSION = YES;
203+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
204+
CLANG_WARN_EMPTY_BODY = YES;
205+
CLANG_WARN_ENUM_CONVERSION = YES;
206+
CLANG_WARN_INT_CONVERSION = YES;
207+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
208+
CLANG_WARN_UNREACHABLE_CODE = YES;
209+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
210+
CODE_SIGN_IDENTITY = "-";
211+
COMBINE_HIDPI_IMAGES = YES;
212+
COPY_PHASE_STRIP = NO;
213+
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
214+
ENABLE_NS_ASSERTIONS = NO;
215+
ENABLE_STRICT_OBJC_MSGSEND = YES;
216+
GCC_C_LANGUAGE_STANDARD = gnu99;
217+
GCC_NO_COMMON_BLOCKS = YES;
218+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
219+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
220+
GCC_WARN_UNDECLARED_SELECTOR = YES;
221+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
222+
GCC_WARN_UNUSED_FUNCTION = YES;
223+
GCC_WARN_UNUSED_VARIABLE = YES;
224+
INFOPLIST_FILE = Tests/Info.plist;
225+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
226+
MACOSX_DEPLOYMENT_TARGET = 10.10;
227+
MTL_ENABLE_DEBUG_INFO = NO;
228+
PRODUCT_BUNDLE_IDENTIFIER = me.pedrovereza.Tests;
229+
PRODUCT_NAME = "$(TARGET_NAME)";
230+
SDKROOT = macosx;
231+
};
232+
name = Release;
233+
};
234+
/* End XCBuildConfiguration section */
235+
236+
/* Begin XCConfigurationList section */
237+
4716C7851C936DCB00F6C1C0 /* Build configuration list for PBXProject "Tests" */ = {
238+
isa = XCConfigurationList;
239+
buildConfigurations = (
240+
4716C7861C936DCB00F6C1C0 /* Debug */,
241+
4716C7871C936DCB00F6C1C0 /* Release */,
242+
);
243+
defaultConfigurationIsVisible = 0;
244+
defaultConfigurationName = Release;
245+
};
246+
4716C7AC1C93750500F6C1C0 /* Build configuration list for PBXNativeTarget "Tests" */ = {
247+
isa = XCConfigurationList;
248+
buildConfigurations = (
249+
4716C7AD1C93750500F6C1C0 /* Debug */,
250+
4716C7AE1C93750500F6C1C0 /* Release */,
251+
);
252+
defaultConfigurationIsVisible = 0;
253+
};
254+
/* End XCConfigurationList section */
255+
};
256+
rootObject = 4716C7821C936DCB00F6C1C0 /* Project object */;
257+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0720"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "4716C7A61C93750500F6C1C0"
18+
BuildableName = "Tests.xctest"
19+
BlueprintName = "Tests"
20+
ReferencedContainer = "container:Tests.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "4716C7A61C93750500F6C1C0"
36+
BuildableName = "Tests.xctest"
37+
BlueprintName = "Tests"
38+
ReferencedContainer = "container:Tests.xcodeproj">
39+
</BuildableReference>
40+
</TestableReference>
41+
</Testables>
42+
<AdditionalOptions>
43+
</AdditionalOptions>
44+
</TestAction>
45+
<LaunchAction
46+
buildConfiguration = "Debug"
47+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
48+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
49+
launchStyle = "0"
50+
useCustomWorkingDirectory = "NO"
51+
ignoresPersistentStateOnLaunch = "NO"
52+
debugDocumentVersioning = "YES"
53+
debugServiceExtension = "internal"
54+
allowLocationSimulation = "YES">
55+
<MacroExpansion>
56+
<BuildableReference
57+
BuildableIdentifier = "primary"
58+
BlueprintIdentifier = "4716C7A61C93750500F6C1C0"
59+
BuildableName = "Tests.xctest"
60+
BlueprintName = "Tests"
61+
ReferencedContainer = "container:Tests.xcodeproj">
62+
</BuildableReference>
63+
</MacroExpansion>
64+
<AdditionalOptions>
65+
</AdditionalOptions>
66+
</LaunchAction>
67+
<ProfileAction
68+
buildConfiguration = "Release"
69+
shouldUseLaunchSchemeArgsEnv = "YES"
70+
savedToolIdentifier = ""
71+
useCustomWorkingDirectory = "NO"
72+
debugDocumentVersioning = "YES">
73+
<MacroExpansion>
74+
<BuildableReference
75+
BuildableIdentifier = "primary"
76+
BlueprintIdentifier = "4716C7A61C93750500F6C1C0"
77+
BuildableName = "Tests.xctest"
78+
BlueprintName = "Tests"
79+
ReferencedContainer = "container:Tests.xcodeproj">
80+
</BuildableReference>
81+
</MacroExpansion>
82+
</ProfileAction>
83+
<AnalyzeAction
84+
buildConfiguration = "Debug">
85+
</AnalyzeAction>
86+
<ArchiveAction
87+
buildConfiguration = "Release"
88+
revealArchiveInOrganizer = "YES">
89+
</ArchiveAction>
90+
</Scheme>

0 commit comments

Comments
 (0)