diff --git a/ExSwift.xcodeproj/project.pbxproj b/ExSwift.xcodeproj/project.pbxproj index ad31243..65409f8 100755 --- a/ExSwift.xcodeproj/project.pbxproj +++ b/ExSwift.xcodeproj/project.pbxproj @@ -8,27 +8,27 @@ /* Begin PBXBuildFile section */ 12168FCA1A22852300ED4105 /* NSDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12168FC91A22852300ED4105 /* NSDate.swift */; }; - 12168FCD1A2285A900ED4105 /* ExSwiftNSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12168FCC1A2285A900ED4105 /* ExSwiftNSDateTests.swift */; }; + 12168FCD1A2285A900ED4105 /* NSDateExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12168FCC1A2285A900ED4105 /* NSDateExtensionsTests.swift */; }; 127C7F061A23154A0038B454 /* NSDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12168FC91A22852300ED4105 /* NSDate.swift */; }; 1E11AF8A1943222D006BCE48 /* ExSwift.h in Headers */ = {isa = PBXBuildFile; fileRef = 1E11AF891943222D006BCE48 /* ExSwift.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 1E11AFA719432236006BCE48 /* ExSwiftDictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFA119432236006BCE48 /* ExSwiftDictionaryTests.swift */; }; - 1E11AFA819432236006BCE48 /* ExSwiftFloatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFA219432236006BCE48 /* ExSwiftFloatTests.swift */; }; - 1E11AFA919432236006BCE48 /* ExSwiftIntTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFA319432236006BCE48 /* ExSwiftIntTests.swift */; }; - 1E11AFAA19432236006BCE48 /* ExSwiftRangeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFA419432236006BCE48 /* ExSwiftRangeTests.swift */; }; - 1E11AFAB19432236006BCE48 /* ExSwiftStringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFA519432236006BCE48 /* ExSwiftStringTests.swift */; }; + 1E11AFA719432236006BCE48 /* DictionaryExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFA119432236006BCE48 /* DictionaryExtensionsTests.swift */; }; + 1E11AFA819432236006BCE48 /* FloatExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFA219432236006BCE48 /* FloatExtensionsTests.swift */; }; + 1E11AFA919432236006BCE48 /* IntExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFA319432236006BCE48 /* IntExtensionsTests.swift */; }; + 1E11AFAA19432236006BCE48 /* RangeExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFA419432236006BCE48 /* RangeExtensionsTests.swift */; }; + 1E11AFAB19432236006BCE48 /* StringExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFA519432236006BCE48 /* StringExtensionsTests.swift */; }; 1E11AFB21943225B006BCE48 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFAC1943225B006BCE48 /* Array.swift */; }; 1E11AFB41943225B006BCE48 /* Dictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFAD1943225B006BCE48 /* Dictionary.swift */; }; 1E11AFB61943225B006BCE48 /* Float.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFAE1943225B006BCE48 /* Float.swift */; }; 1E11AFB81943225B006BCE48 /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFAF1943225B006BCE48 /* Int.swift */; }; 1E11AFBA1943225B006BCE48 /* Range.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFB01943225B006BCE48 /* Range.swift */; }; 1E11AFBC1943225B006BCE48 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFB11943225B006BCE48 /* String.swift */; }; - 1E1DABF5197ECF030070CFBC /* ExSwiftArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFA019432236006BCE48 /* ExSwiftArrayTests.swift */; }; + 1E1DABF5197ECF030070CFBC /* ArrayExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFA019432236006BCE48 /* ArrayExtensionsTests.swift */; }; 1E48E61E1973ED07006FEEC8 /* Double.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E48E61D1973ED07006FEEC8 /* Double.swift */; }; 1E48E61F1973ED07006FEEC8 /* Double.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E48E61D1973ED07006FEEC8 /* Double.swift */; }; - 1E48E6231973ED22006FEEC8 /* ExSwiftDoubleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E48E6221973ED22006FEEC8 /* ExSwiftDoubleTests.swift */; }; + 1E48E6231973ED22006FEEC8 /* DoubleExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E48E6221973ED22006FEEC8 /* DoubleExtensionsTests.swift */; }; 1EA5F68A194387CA00E8A40F /* ExSwiftTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EA5F689194387CA00E8A40F /* ExSwiftTests.swift */; }; 1EC241FC1946E91B0047109A /* NSArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EC241FB1946E91B0047109A /* NSArray.swift */; }; - 1EC241FE1946E92E0047109A /* ExSwiftNSArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EC241FD1946E92E0047109A /* ExSwiftNSArrayTests.swift */; }; + 1EC241FE1946E92E0047109A /* NSArrayExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EC241FD1946E92E0047109A /* NSArrayExtensionsTests.swift */; }; 1ED536841943863100BDA94E /* ExSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ED536831943863100BDA94E /* ExSwift.swift */; }; 2EB34F05195473AC00A8D2AF /* ExSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ED536831943863100BDA94E /* ExSwift.swift */; }; 2EB34F06195473AC00A8D2AF /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E11AFAC1943225B006BCE48 /* Array.swift */; }; @@ -40,27 +40,27 @@ 2EB34F0C195473AC00A8D2AF /* NSArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EC241FB1946E91B0047109A /* NSArray.swift */; }; 3C0AB978195C7FAF0009BDA0 /* Sequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C0AB977195C7FAF0009BDA0 /* Sequence.swift */; }; 3C0AB979195C7FB20009BDA0 /* Sequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C0AB977195C7FAF0009BDA0 /* Sequence.swift */; }; - 3C0AB97D195C7FBC0009BDA0 /* ExSwiftSequenceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C0AB97C195C7FBC0009BDA0 /* ExSwiftSequenceTests.swift */; }; + 3C0AB97D195C7FBC0009BDA0 /* SequenceExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3C0AB97C195C7FBC0009BDA0 /* SequenceExtensionsTests.swift */; }; 6B4C508C1A94BD8A400FF55B /* Pods_ExSwiftTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3400589621EC883044639A12 /* Pods_ExSwiftTests.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; - CC633BA61A37142900341557 /* ExSwiftCharacterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC633BA51A37142900341557 /* ExSwiftCharacterTests.swift */; }; + CC633BA61A37142900341557 /* CharacterExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC633BA51A37142900341557 /* CharacterExtensionsTests.swift */; }; CC633BA71A37144E00341557 /* Character.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC8C1D701A365CA6003D386E /* Character.swift */; }; CC8C1D711A365CA6003D386E /* Character.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC8C1D701A365CA6003D386E /* Character.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 12168FC91A22852300ED4105 /* NSDate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSDate.swift; sourceTree = ""; }; - 12168FCC1A2285A900ED4105 /* ExSwiftNSDateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExSwiftNSDateTests.swift; sourceTree = ""; }; + 12168FCC1A2285A900ED4105 /* NSDateExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSDateExtensionsTests.swift; sourceTree = ""; }; 1E11AF841943222D006BCE48 /* ExSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ExSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 1E11AF881943222D006BCE48 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 1E11AF891943222D006BCE48 /* ExSwift.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ExSwift.h; sourceTree = ""; }; 1E11AF8F1943222D006BCE48 /* ExSwiftTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ExSwiftTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 1E11AF951943222D006BCE48 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 1E11AFA019432236006BCE48 /* ExSwiftArrayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExSwiftArrayTests.swift; sourceTree = ""; }; - 1E11AFA119432236006BCE48 /* ExSwiftDictionaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExSwiftDictionaryTests.swift; sourceTree = ""; }; - 1E11AFA219432236006BCE48 /* ExSwiftFloatTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExSwiftFloatTests.swift; sourceTree = ""; }; - 1E11AFA319432236006BCE48 /* ExSwiftIntTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExSwiftIntTests.swift; sourceTree = ""; }; - 1E11AFA419432236006BCE48 /* ExSwiftRangeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExSwiftRangeTests.swift; sourceTree = ""; }; - 1E11AFA519432236006BCE48 /* ExSwiftStringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExSwiftStringTests.swift; sourceTree = ""; }; + 1E11AFA019432236006BCE48 /* ArrayExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayExtensionsTests.swift; sourceTree = ""; }; + 1E11AFA119432236006BCE48 /* DictionaryExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DictionaryExtensionsTests.swift; sourceTree = ""; }; + 1E11AFA219432236006BCE48 /* FloatExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FloatExtensionsTests.swift; sourceTree = ""; }; + 1E11AFA319432236006BCE48 /* IntExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IntExtensionsTests.swift; sourceTree = ""; }; + 1E11AFA419432236006BCE48 /* RangeExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RangeExtensionsTests.swift; sourceTree = ""; }; + 1E11AFA519432236006BCE48 /* StringExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtensionsTests.swift; sourceTree = ""; }; 1E11AFAC1943225B006BCE48 /* Array.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 1E11AFAD1943225B006BCE48 /* Dictionary.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Dictionary.swift; sourceTree = ""; }; 1E11AFAE1943225B006BCE48 /* Float.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Float.swift; sourceTree = ""; }; @@ -68,16 +68,16 @@ 1E11AFB01943225B006BCE48 /* Range.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Range.swift; sourceTree = ""; }; 1E11AFB11943225B006BCE48 /* String.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = String.swift; sourceTree = ""; }; 1E48E61D1973ED07006FEEC8 /* Double.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Double.swift; sourceTree = ""; }; - 1E48E6221973ED22006FEEC8 /* ExSwiftDoubleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExSwiftDoubleTests.swift; sourceTree = ""; }; + 1E48E6221973ED22006FEEC8 /* DoubleExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DoubleExtensionsTests.swift; sourceTree = ""; }; 1EA5F689194387CA00E8A40F /* ExSwiftTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExSwiftTests.swift; sourceTree = ""; }; 1EC241FB1946E91B0047109A /* NSArray.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSArray.swift; sourceTree = ""; }; - 1EC241FD1946E92E0047109A /* ExSwiftNSArrayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExSwiftNSArrayTests.swift; sourceTree = ""; }; + 1EC241FD1946E92E0047109A /* NSArrayExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSArrayExtensionsTests.swift; sourceTree = ""; }; 1ED536831943863100BDA94E /* ExSwift.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExSwift.swift; sourceTree = ""; }; 3400589621EC883044639A12 /* Pods_ExSwiftTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ExSwiftTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 3C0AB977195C7FAF0009BDA0 /* Sequence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Sequence.swift; sourceTree = ""; }; - 3C0AB97C195C7FBC0009BDA0 /* ExSwiftSequenceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExSwiftSequenceTests.swift; sourceTree = ""; }; + 3C0AB97C195C7FBC0009BDA0 /* SequenceExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SequenceExtensionsTests.swift; sourceTree = ""; }; 47BFD91627F26E53E2F0CF12 /* Pods-ExSwiftTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExSwiftTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-ExSwiftTests/Pods-ExSwiftTests.release.xcconfig"; sourceTree = ""; }; - CC633BA51A37142900341557 /* ExSwiftCharacterTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExSwiftCharacterTests.swift; sourceTree = ""; }; + CC633BA51A37142900341557 /* CharacterExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CharacterExtensionsTests.swift; sourceTree = ""; }; CC8C1D701A365CA6003D386E /* Character.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Character.swift; sourceTree = ""; }; FF3986903A1926706883B2B5 /* Pods-ExSwiftTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ExSwiftTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ExSwiftTests/Pods-ExSwiftTests.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -153,18 +153,18 @@ 1E11AF931943222D006BCE48 /* ExSwiftTests */ = { isa = PBXGroup; children = ( - 3C0AB97C195C7FBC0009BDA0 /* ExSwiftSequenceTests.swift */, - 1E11AFA019432236006BCE48 /* ExSwiftArrayTests.swift */, - CC633BA51A37142900341557 /* ExSwiftCharacterTests.swift */, - 1E11AFA119432236006BCE48 /* ExSwiftDictionaryTests.swift */, - 1E48E6221973ED22006FEEC8 /* ExSwiftDoubleTests.swift */, - 1E11AFA219432236006BCE48 /* ExSwiftFloatTests.swift */, - 1E11AFA319432236006BCE48 /* ExSwiftIntTests.swift */, - 1E11AFA419432236006BCE48 /* ExSwiftRangeTests.swift */, - 1E11AFA519432236006BCE48 /* ExSwiftStringTests.swift */, + 3C0AB97C195C7FBC0009BDA0 /* SequenceExtensionsTests.swift */, + 1E11AFA019432236006BCE48 /* ArrayExtensionsTests.swift */, + CC633BA51A37142900341557 /* CharacterExtensionsTests.swift */, + 1E11AFA119432236006BCE48 /* DictionaryExtensionsTests.swift */, + 1E48E6221973ED22006FEEC8 /* DoubleExtensionsTests.swift */, + 1E11AFA219432236006BCE48 /* FloatExtensionsTests.swift */, + 1E11AFA319432236006BCE48 /* IntExtensionsTests.swift */, + 1E11AFA419432236006BCE48 /* RangeExtensionsTests.swift */, + 1E11AFA519432236006BCE48 /* StringExtensionsTests.swift */, 1EA5F689194387CA00E8A40F /* ExSwiftTests.swift */, - 1EC241FD1946E92E0047109A /* ExSwiftNSArrayTests.swift */, - 12168FCC1A2285A900ED4105 /* ExSwiftNSDateTests.swift */, + 1EC241FD1946E92E0047109A /* NSArrayExtensionsTests.swift */, + 12168FCC1A2285A900ED4105 /* NSDateExtensionsTests.swift */, 1E11AF941943222D006BCE48 /* Supporting Files */, ); path = ExSwiftTests; @@ -373,28 +373,28 @@ buildActionMask = 2147483647; files = ( 127C7F061A23154A0038B454 /* NSDate.swift in Sources */, - 1E1DABF5197ECF030070CFBC /* ExSwiftArrayTests.swift in Sources */, - 1E11AFAA19432236006BCE48 /* ExSwiftRangeTests.swift in Sources */, + 1E1DABF5197ECF030070CFBC /* ArrayExtensionsTests.swift in Sources */, + 1E11AFAA19432236006BCE48 /* RangeExtensionsTests.swift in Sources */, 2EB34F09195473AC00A8D2AF /* Int.swift in Sources */, 2EB34F06195473AC00A8D2AF /* Array.swift in Sources */, - 1EC241FE1946E92E0047109A /* ExSwiftNSArrayTests.swift in Sources */, + 1EC241FE1946E92E0047109A /* NSArrayExtensionsTests.swift in Sources */, 2EB34F07195473AC00A8D2AF /* Dictionary.swift in Sources */, 3C0AB979195C7FB20009BDA0 /* Sequence.swift in Sources */, - 1E48E6231973ED22006FEEC8 /* ExSwiftDoubleTests.swift in Sources */, - 1E11AFA819432236006BCE48 /* ExSwiftFloatTests.swift in Sources */, - 1E11AFA719432236006BCE48 /* ExSwiftDictionaryTests.swift in Sources */, + 1E48E6231973ED22006FEEC8 /* DoubleExtensionsTests.swift in Sources */, + 1E11AFA819432236006BCE48 /* FloatExtensionsTests.swift in Sources */, + 1E11AFA719432236006BCE48 /* DictionaryExtensionsTests.swift in Sources */, 1E48E61F1973ED07006FEEC8 /* Double.swift in Sources */, - 3C0AB97D195C7FBC0009BDA0 /* ExSwiftSequenceTests.swift in Sources */, + 3C0AB97D195C7FBC0009BDA0 /* SequenceExtensionsTests.swift in Sources */, 2EB34F0C195473AC00A8D2AF /* NSArray.swift in Sources */, CC633BA71A37144E00341557 /* Character.swift in Sources */, 2EB34F05195473AC00A8D2AF /* ExSwift.swift in Sources */, 2EB34F08195473AC00A8D2AF /* Float.swift in Sources */, - 12168FCD1A2285A900ED4105 /* ExSwiftNSDateTests.swift in Sources */, - 1E11AFAB19432236006BCE48 /* ExSwiftStringTests.swift in Sources */, - 1E11AFA919432236006BCE48 /* ExSwiftIntTests.swift in Sources */, + 12168FCD1A2285A900ED4105 /* NSDateExtensionsTests.swift in Sources */, + 1E11AFAB19432236006BCE48 /* StringExtensionsTests.swift in Sources */, + 1E11AFA919432236006BCE48 /* IntExtensionsTests.swift in Sources */, 2EB34F0B195473AC00A8D2AF /* String.swift in Sources */, 1EA5F68A194387CA00E8A40F /* ExSwiftTests.swift in Sources */, - CC633BA61A37142900341557 /* ExSwiftCharacterTests.swift in Sources */, + CC633BA61A37142900341557 /* CharacterExtensionsTests.swift in Sources */, 2EB34F0A195473AC00A8D2AF /* Range.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/ExSwift.xcworkspace/contents.xcworkspacedata b/ExSwift.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..6d7f951 --- /dev/null +++ b/ExSwift.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,10 @@ + + + + + + + diff --git a/ExSwiftTests/ArrayExtensionsTests.swift b/ExSwiftTests/ArrayExtensionsTests.swift new file mode 100644 index 0000000..38228d3 --- /dev/null +++ b/ExSwiftTests/ArrayExtensionsTests.swift @@ -0,0 +1,1134 @@ +// +// ArrayExtensionsTests.swift +// ExtensionsTests +// +// Created by pNre on 03/06/14. +// Copyright (c) 2014 pNre. All rights reserved. +// + +import Quick +import Nimble + +class ArrayExtensionsSpec: QuickSpec { + + var intArray: [Int] = [] + var stringArray: [String] = [] + + override func spec() { + + beforeEach { () -> () in + + self.intArray = [Int](1...5) + self.stringArray = ["A", "B", "C", "D", "E", "F"] + + } + + /** + * Array.get + */ + describe("get") { + + it("in bounds") { + + for i in enumerate(self.intArray) { + expect(self.intArray.get(i.index)) == (i.element) + } + + } + + it("out of bounds") { + + expect(self.intArray.get(-1)).to(beNil()) + + expect(self.intArray.get(self.intArray.count)).to(beNil()) + + } + + } + + /** + * Array.sortUsing + */ + describe("sortUsing") { + + it("default item comparison") { + + expect(self.intArray.sortUsing { $0 }) == [1, 2, 3, 4, 5] + + } + + it("mapped item") { + + expect(self.intArray.sortUsing { $0 % 2 }) == [2, 4, 1, 3, 5] + expect(self.intArray.sortUsing { -$0 }) == self.intArray.reverse() + + } + + } + + /** + * Array.reject + */ + describe("reject") { + + it("all/none") { + + expect(self.intArray.reject { _ in true }) == [] + + expect(self.intArray.reject { _ in false }) == self.intArray + + } + + it("misc") { + + expect(self.intArray.reject { obj in obj > 3 }) == [1, 2, 3] + + expect(self.intArray.reject { obj in obj % 2 == 0 }) == [1, 3, 5] + + } + + } + + /** + * Array.each + */ + describe("each") { + + it("object param") { + + var data = [Int]() + + self.intArray.each { data.append($0) } + + expect(data) == self.intArray + + } + + it("index param") { + + var data = [Int]() + + self.intArray.each { index, obj in data.append(index) } + + expect(data) == [Int](0...4) + + } + + } + + /** + * Array.contains + */ + describe("contains") { + + it("one item") { + + expect(self.intArray.contains(10)).to(beFalse()) + + expect(self.intArray.contains(4)).to(beTrue()) + + } + + it("more than one item") { + + // Contains 1, doesn't contain 10 + expect(self.intArray.contains(1, 10)).to(beFalse()) + + // Contains both 1, 2 + expect(self.intArray.contains(1, 2)).to(beTrue()) + + // Doesn't contain 6, 7, 8 + expect(self.intArray.contains(6, 7, 8)).to(beFalse()) + + } + + it("item of an invalid type") { + + expect(self.intArray.contains("A")).to(beFalse()) + + } + + } + + /** + * Array.indexOf + */ + describe("indexOf") { + + it("with an object") { + + expect(self.intArray.indexOf(1)) == 0 + expect(self.intArray.indexOf(5)) == 4 + + expect(self.intArray.indexOf(self.intArray[2])) == 2 + + expect(self.intArray.indexOf(50)).to(beNil()) + + } + + it("with matching block") { + + expect(self.intArray.indexOf { $0 % 2 == 0 }) == 1 + + expect(self.intArray.indexOf { $0 > 10 }).to(beNil()) + + } + + } + + /** + * Array.lastIndexOf + */ + describe("lastIndexOf") { + + var arrayWithDuplicates: [Int] = [] + + beforeEach { + + arrayWithDuplicates = [1, 1, 2, 2, 3, 4, 1] + + } + + it("with an object") { + + expect(arrayWithDuplicates.lastIndexOf(1)) == 6 + expect(arrayWithDuplicates.lastIndexOf(4)) == 5 + + expect(arrayWithDuplicates.lastIndexOf(arrayWithDuplicates[2])) == 3 + + expect(arrayWithDuplicates.lastIndexOf(50)).to(beNil()) + + } + + } + + /** + * Array.max + */ + describe("max") { + + it("comparable array") { + + expect(self.intArray.max() as Int) == 5 + + } + + } + + /** + * Array.min + */ + describe("min") { + + it("comparable array") { + + expect(self.intArray.min() as Int) == 1 + + } + + } + + /** + * Array.at + */ + describe("at") { + + it("at") { + + expect(self.intArray.at(0, 2)) == [1, 3] + + } + + it("subscript") { + + expect(self.intArray[0, 2, 1]) == [1, 3, 2] + + } + + } + + /** + * Array.unique/uniqueBy + */ + describe("unique/uniqueBy") { + + var arrayWithDuplicates: [Int] = [] + + beforeEach { + + arrayWithDuplicates = [1, 1, 2, 2, 3, 4] + + } + + it("unique") { + + expect(arrayWithDuplicates.unique() as [Int]) == [1, 2, 3, 4] + + } + + it("uniqueBy") { + + expect(arrayWithDuplicates.uniqueBy { $0 }) == arrayWithDuplicates.unique() + + expect(arrayWithDuplicates.uniqueBy { $0 % 2 }) == [1, 2] + + expect(arrayWithDuplicates.uniqueBy { $0 % 3 }) == [1, 2, 3] + + expect(arrayWithDuplicates.uniqueBy { $0 < 3 }) == [1, 3] + + } + + } + + /** + * Array.take/takeWhile + */ + describe("take/takeWhile") { + + it("take") { + + expect(self.intArray.take(2)) == self.intArray[0..2] + expect(self.intArray.take(0)) == [] + + } + + it("take out of bounds") { + + expect(self.intArray.take(6)) == self.intArray + expect(self.intArray.take(-1)) == [] + + } + + it("takeWhile") { + + expect(self.intArray.takeWhile { $0 < 3 }) == [1, 2] + + expect(self.intArray.takeWhile { $0 % 2 == 0 }) == [] + + } + + } + + /** + * Array.skip/skipWhile + */ + describe("skip/skipWhile") { + + it("skip") { + + expect(self.intArray.skip(2)) == self.intArray[2.. 0 }) == [] + + } + + } + + /** + * Array.countBy + */ + describe("countBy") { + + it("countBy") { + + let count_1 = self.intArray.countBy { + return $0 % 2 == 0 ? "even" : "odd" + } + + expect(count_1) == ["even": 2, "odd": 3] + + let count_2 = self.intArray.countBy { param -> Int in + return 0 + } + + expect(count_2) == [0: self.intArray.count] + + } + + } + + /** + * Array.difference + */ + describe("difference") { + + it("method") { + + expect(self.intArray.difference([3, 4])) == [1, 2, 5] + + expect(self.intArray.difference([3], [4])) == [1, 2, 5] + + expect(self.intArray.difference([])) == self.intArray + + } + + it("operator") { + + expect(self.intArray - [3, 4]) == [1, 2, 5] + + expect(self.intArray - [3] - [4]) == [1, 2, 5] + + expect(self.intArray - []) == self.intArray + + } + + } + + /** + * Array.intersection + */ + describe("intersection") { + + it("method") { + + expect(self.intArray.intersection([])) == [] + + expect(self.intArray.intersection([1])) == [1] + + expect(self.intArray.intersection([1, 2], [1, 2], [1, 2, 3])) == [1, 2] + + } + + it("operator") { + + expect(self.intArray & []) == [] + + expect(self.intArray & [1]) == [1] + + expect(self.intArray & [1, 2] & [1, 2] & [1, 2, 3]) == [1, 2] + + } + + } + + /** + * Array.union + */ + describe("union") { + + it("method") { + + expect(self.intArray.union([])) == self.intArray + + expect(self.intArray.union([1])) == self.intArray + + expect(self.intArray.union([1, 5], [6], [7, 4])) == [1, 2, 3, 4, 5, 6, 7] + + } + + it("operator") { + + expect(self.intArray | []) == self.intArray + + expect(self.intArray | [1]) == self.intArray + + expect(self.intArray | [1, 5] | [6] | [7, 4]) == [1, 2, 3, 4, 5, 6, 7] + + } + + } + + /** + * Array duplication + */ + describe("duplication") { + + it("operator") { + + expect([1] * 3) == [1, 1, 1] + + expect(self.intArray * 0) == [] + expect(self.intArray * 1) == self.intArray + + } + + } + + /** + * Array.tail + */ + describe("tail") { + + it("in bounds") { + + expect(self.intArray.tail(0)) == [] + + expect(self.intArray.tail(3)) == [3, 4, 5] + + } + + it("out of bounds") { + + expect(self.intArray.tail(10)) == self.intArray + + } + + } + + /** + * Array.pop + */ + describe("pop") { + + it("non empty array") { + + expect(self.intArray.pop()) == 5 + expect(self.intArray) == [1, 2, 3, 4] + + } + + it("empty array") { + + var emptyArray = [Int]() + + expect(emptyArray.pop()).to(beNil()) + + } + + } + + /** + * Array.push + */ + describe("push") { + + it("push") { + + self.intArray.push(10) + + expect(self.intArray.last) == 10 + + } + + } + + /** + * Array.shift + */ + describe("shift") { + + it("non empty array") { + + expect(self.intArray.shift()) == 1 + expect(self.intArray) == [2, 3, 4, 5] + + } + + it("empty array") { + + var emptyArray = [Int]() + + expect(emptyArray.shift()).to(beNil()) + + } + + } + + /** + * Array.unshift + */ + describe("unshift") { + + it("unshift") { + + self.intArray.unshift(10) + + expect(self.intArray) == [10, 1, 2, 3, 4, 5] + + } + + } + + /** + * Array.remove + */ + describe("remove") { + + it("method") { + + self.intArray.remove(1) + + expect(self.intArray) == [2, 3, 4, 5] + + self.intArray.remove(6) + + expect(self.intArray) == [2, 3, 4, 5] + + } + + it("operator") { + + expect(self.intArray - 1) == [2, 3, 4, 5] + + expect(self.intArray - 6) == [1, 2, 3, 4, 5] + + } + } + + /** + * Array.toDictionary + */ + describe("toDictionary") { + + it("map values to keys") { + + let dictionary = self.intArray.toDictionary { + + return "Number \($0)" + + } + + for i in enumerate(self.intArray) { + + expect(dictionary["Number \(i.element)"]) == i.element + + } + + } + + it("map keys and values") { + + let dictionary = self.intArray.toDictionary { (element) -> (Int, String)? in + + if (element > 2) { + return nil + } + + return (element, "Number \(element)") + + } + + expect(dictionary[1]) == "Number 1" + expect(dictionary[2]) == "Number 2" + + expect(dictionary.keys.array - [1, 2]) == [] + + } + + } + + /** + * Array.implode + */ + describe("implode") { + + it("method") { + + expect(self.stringArray.implode("")) == "ABCDEF" + expect(self.stringArray.implode("*")) == "A*B*C*D*E*F" + + } + + it("operator") { + + expect(self.stringArray * "") == "ABCDEF" + expect(self.stringArray * "*") == "A*B*C*D*E*F" + + } + + } + + /** + * Array.flatten + */ + describe("flatten") { + + var multidimensionalArray: NSArray = [] + + beforeEach { () -> () in + + multidimensionalArray = [5, [6, [7]], 8] + + } + + it("flatten") { + + expect(multidimensionalArray.flatten() as [Int]) == [5, 6, 7, 8] + expect((multidimensionalArray.flattenAny() as! [Int])) == [5, 6, 7, 8] + + } + + } + + /** + * Array.minBy + */ + it("minBy") { + + expect(self.intArray.minBy { $0 }) == 1 + + expect(self.intArray.minBy { -$0 }) == 5 + + expect(self.intArray.minBy { $0 % 4 }) == 4 + + expect(self.intArray.minBy { $0 % 2 }) == 2 + + } + + /** + * Array.maxBy + */ + it("maxBy") { + + expect(self.intArray.maxBy { $0 }) == 5 + + expect(self.intArray.maxBy { -$0 }) == 1 + + expect(self.intArray.maxBy { $0 % 4 }) == 3 + + expect(self.intArray.maxBy { $0 % 3 }) == 2 + + } + + /** + * Array.zip + */ + it("zip") { + + let zipped = self.stringArray.zip(self.intArray) + + expect(zipped[0].first as? String) == "A" + expect(zipped[0].last as? Int) == 1 + + expect(zipped[1].first as? String) == "B" + expect(zipped[1].last as? Int) == 2 + + expect(zipped.last!.first as? String) == "E" + expect(zipped.last!.last as? Int) == 5 + + } + + /** + * Array.sample + */ + it("sample") { + + // 0 objects + let zero = self.intArray.sample(size: 0) + + expect(zero).to(beEmpty()) + + // 1 object + let one = self.intArray.sample()[0] + + expect(self.intArray).to(contain(one)) + + // n > 1 objects + let sampled = self.intArray.sample(size: 3) + + for item in sampled { + expect(self.intArray).to(contain(item)) + } + + } + + /** + * Array.groupBy + */ + it("groupBy") { + + let group = self.intArray.groupBy(groupingFunction: { + (value: Int) -> Bool in + return value > 3 + }) + + expect(group.keys.array) == [false, true] + + expect(group[true]) == [4, 5] + expect(group[false]) == [1, 2, 3] + + } + + /** + * Array.countWhere + */ + it("countWhere") { + + expect(self.intArray.countWhere { value in true }) == self.intArray.count + expect(self.intArray.countWhere { value in false }) == 0 + + expect(self.intArray.countWhere { value in value % 2 == 0 }) == 2 + + } + + /** + * Array.takeFirst + */ + it("takeFirst") { + + expect(self.intArray.takeFirst { value in true }) == 1 + expect(self.intArray.takeFirst { value in false }).to(beNil()) + + expect(self.intArray.takeFirst { $0 % 2 == 0 }) == 2 + expect(self.intArray.takeFirst { $0 > 10 }).to(beNil()) + + } + + /** + * Array.fill + */ + it("fill") { + + self.intArray.fill(0) + + for object in self.intArray { + expect(object) == 0 + } + + var emptyArray: [String] = [] + emptyArray.fill("x") + + expect(emptyArray) == [] + + } + + /** + * Array.insert + */ + it("insert") { + + self.intArray.insert([6, 7, 8], atIndex: 1) + + expect(self.intArray) == [1, 6, 7, 8, 2, 3, 4, 5] + + self.intArray.insert([9], atIndex: 10) + + expect(self.intArray) == [1, 6, 7, 8, 2, 3, 4, 5, 9] + + self.intArray.insert([0], atIndex: -2) + + expect(self.intArray) == [0, 1, 6, 7, 8, 2, 3, 4, 5, 9] + + } + + /** + * Array[] + */ + describe("subscript") { + + it("half open interval") { + + expect(self.intArray[0..<0]) == [] + expect(self.intArray[0..<1]) == [1] + expect(self.intArray[0..<2]) == [1, 2] + + } + + it("interval") { + + expect(self.intArray[0...0]) == [1] + expect(self.intArray[0...1]) == [1, 2] + expect(self.intArray[0...2]) == [1, 2, 3] + + } + + it("list of indices") { + + expect(self.intArray[0, 1]) == [1, 2] + expect(self.intArray[2, 4]) == [3, 5] + + } + + } + + /** + * Array.shuffled + */ + it("shuffled") { + + expect(self.intArray - self.intArray.shuffled()) == [] + + } + + /** + * Array.shuffle + */ + it("shuffled") { + + var array = self.intArray + + self.intArray.shuffle() + + expect(self.intArray - array) == [] + + } + + /** + * Array.mapFilter + */ + it("mapFilter") { + + let mapped = self.intArray.mapFilter { value in + return value > 3 ? nil : value + 1 + } + + expect(mapped) == [2, 3, 4] + + } + + /** + * Array.mapAccum + */ + it("mapAccum") { + + let (accumulated, mapped) = self.intArray.mapAccum(0) { accumulator, value in + return (accumulator + value, value - 1) + } + + expect(accumulated) == self.intArray.reduce(+) + expect(mapped) == self.intArray.map { $0 - 1 } + + } + + /** + * Array.cycle + */ + it("cycle") { + + var sum = 0 + + self.intArray.cycle(n: 2) { + sum += $0 + } + + expect(sum) == self.intArray.reduce(0, combine: +) * 2 + + sum = 0 + + self.intArray.cycle(n: 0) { + sum += $0 + } + + expect(sum) == 0 + + self.intArray.cycle(n: -1) { + sum += $0 + } + + expect(sum) == 0 + + } + + /** + * Array.partition + */ + it("partition") { + + expect(self.intArray.partition(2)) == [[1, 2], [3, 4]] + + expect(self.intArray.partition(2, step: 1)) == [[1, 2], [2, 3], [3, 4], [4, 5]] + + expect(self.intArray.partition(2, step: 1, pad: nil)) == [[1, 2], [2, 3], [3, 4], [4, 5], [5]] + expect(self.intArray.partition(4, step: 1, pad: nil)) == [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5]] + + expect(self.intArray.partition(2, step: 1, pad: [6, 7, 8])) == [[1, 2], [2, 3], [3, 4], [4, 5], [5, 6]] + expect(self.intArray.partition(4, step: 3, pad: [6])) == [[1, 2, 3, 4], [4, 5, 6]] + + expect(self.intArray.partition(2, pad: [6])) == [[1, 2], [3, 4], [5, 6]] + + expect([1, 2, 3, 4, 5, 6].partition(2, step: 4)) == [[1, 2], [5, 6]] + + expect(self.intArray.partition(10)) == [[]] + + } + + /** + * Array.partitionAll + */ + it("partitionAll") { + + expect(self.intArray.partitionAll(2, step: 1)) == [[1, 2], [2, 3], [3, 4], [4, 5], [5]] + + expect(self.intArray.partitionAll(2)) == [[1, 2], [3, 4], [5]] + + expect(self.intArray.partitionAll(4, step: 1)) == [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5], [4, 5], [5]] + + } + + /** + * Array.partitionBy + */ + it("partitionBy") { + + expect(self.intArray.partitionBy { value in false }) == [self.intArray] + expect(self.intArray.partitionBy { value in true }) == [self.intArray] + + expect([1, 2, 4, 3, 5, 6].partitionBy { $0 % 2 == 0 }) == [[1], [2, 4], [3, 5], [6]] + + expect([1, 7, 3, 6, 10, 12].partitionBy { $0 % 3 }) == [[1, 7], [3, 6], [10], [12]] + + } + + /** + * Array.repeatedCombination + */ + it("repeatedCombination") { + + var array = [1, 2, 3] + + expect(array.repeatedCombination(-1)) == [] + + expect(array.repeatedCombination(0)) == [[]] + + expect(array.repeatedCombination(1)) == [[1], [2], [3]] + expect(array.repeatedCombination(2)) == [[1, 1], [1, 2], [1, 3], [2, 2], [2, 3], [3, 3]] + expect(array.repeatedCombination(3)) == [[1, 1, 1],[1, 1, 2], [1, 1, 3], [1, 2, 2], [1, 2, 3], [1, 3, 3], [2, 2, 2], [2, 2, 3], [2, 3, 3], [3, 3, 3]] + expect(array.repeatedCombination(4)) == [[1, 1, 1, 1], [1, 1, 1, 2], [1, 1, 1, 3], [1, 1, 2, 2], [1, 1, 2, 3], [1, 1, 3, 3], [1, 2, 2, 2], [1, 2, 2, 3], [1, 2, 3, 3], [1, 3, 3, 3], [2, 2, 2, 2], [2, 2, 2, 3], [2, 2, 3, 3], [2, 3, 3, 3], [3, 3, 3, 3]] + + } + + /** + * Array.combination + */ + it("combination") { + + expect(self.intArray.combination(-1)) == [] + + expect(self.intArray.combination(0)) == [[]] + + expect(self.intArray.combination(1)) == [[1], [2], [3], [4], [5]] + expect(self.intArray.combination(2)) == [[1, 2], [1, 3], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5]] + expect(self.intArray.combination(3)) == [[1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 3, 4], [1, 3, 5], [1, 4, 5], [2, 3, 4], [2, 3, 5], [2, 4, 5], [3, 4, 5]] + expect(self.intArray.combination(4)) == [[1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 4, 5], [1, 3, 4, 5], [2, 3, 4, 5]] + expect(self.intArray.combination(5)) == [[1, 2, 3, 4, 5]] + expect(self.intArray.combination(6)) == [] + + } + + /** + * Array.transposition + */ + it("transposition") { + + var arrays: [[Int]] = [self.intArray] * self.intArray.count + + var arraysTransposition: [[Int]] = [].transposition(arrays) + arrays.eachIndex { i in + arrays[0].eachIndex { j in + expect(arrays[i][j]) == arraysTransposition[j][i] + } + } + + var jagged: [[String]] = [["a", "b", "c"], ["d", "e"], ["f", "g", "h"]] + var jaggedTransposition = [].transposition(jagged) + + expect(jaggedTransposition) == [["a", "d", "f"], ["b", "e", "g"], ["c", "h"]] + + } + + /** + * Array.permutation + */ + it("permutation") { + + 1.upTo(self.intArray.count) { i in + var permutations: [[Int]] = self.intArray.permutation(i) + var factorial = 1 + + for j in 1...i { + factorial *= j + } + + expect(permutations.count) == self.intArray.combination(i).count * factorial + + var mappedPermutations: [Int] = permutations.map({ (i: [Int]) -> [Int] in i.unique()}).flatten() + var flattenedPermutations: [Int] = permutations.flatten() + + expect(mappedPermutations) == flattenedPermutations + expect(permutations.flatten().all({$0 >= 1 && $0 <= 5})).to(beTrue()) + expect(permutations.unique()) == permutations + } + + expect(self.intArray.permutation(-1)) == [] + expect(self.intArray.permutation(0)) == [[]] + expect(self.intArray.permutation(self.intArray.count + 1)) == [] + + } + + /** + * Array.repeatedPermutation + */ + it("repeatedPermutation") { + + var shortArray = [1, 2] + + expect(shortArray.repeatedPermutation(0)) == [] + expect(shortArray.repeatedPermutation(1)) == [[1], [2]] + expect(shortArray.repeatedPermutation(2)) == [[1, 1], [1, 2], [2, 1], [2, 2]] + expect(shortArray.repeatedPermutation(3)) == [[1, 1, 1], [1, 1, 2], [1, 2, 1], [1, 2, 2], [2, 1, 1], [2, 1, 2], [2, 2, 1], [2, 2, 2]] + + } + + /** + * Array.bSearch + */ + describe("bSearch") { + + it("findMin") { + + 1.upTo(10) { arraySize in + + var testArray: [Int] = [] + + 1.upTo(arraySize) { i in + testArray += [i] + } + + for i in testArray { + expect(testArray.bSearch({ $0 >= i })) == i + } + + } + + expect(self.intArray.bSearch({ $0 >= 101 })).to(beNil()) + + expect(self.intArray.bSearch({ $0 >= 0 })) == 1 + + expect([].bSearch({ true })).to(beNil()) + + } + + it("findAny") { + + 1.upTo(10) { arraySize in + + var testArray: [Int] = [] + + 1.upTo(arraySize) { i in + testArray += [i] + } + + for i in testArray { + expect(testArray.bSearch({ $0 - i })) == i + } + + } + + expect(self.intArray.bSearch({ $0 - (self.intArray.max() + 1) })).to(beNil()) + expect(self.intArray.bSearch({ $0 - (self.intArray.min() - 1) })).to(beNil()) + + expect([Int]().bSearch({ $0 })).to(beNil()) + + } + + } + + } + +} diff --git a/ExSwiftTests/CharacterExtensionsTests.swift b/ExSwiftTests/CharacterExtensionsTests.swift new file mode 100644 index 0000000..3707c6a --- /dev/null +++ b/ExSwiftTests/CharacterExtensionsTests.swift @@ -0,0 +1,26 @@ +// +// CharacterExtensions.swift +// ExSwift +// +// Created by Cenny Davidsson on 2014-12-09. +// Copyright (c) 2014 pNre. All rights reserved. +// + +import Quick +import Nimble + +class CharacterExtensionsSpec: QuickSpec { + + override func spec() { + + it("toInt") { + + expect(Character("7").toInt()) == 7 + + expect(Character("a").toInt()).to(beNil()) + + } + + } + +} diff --git a/ExSwiftTests/DictionaryExtensionsTests.swift b/ExSwiftTests/DictionaryExtensionsTests.swift new file mode 100644 index 0000000..9474d01 --- /dev/null +++ b/ExSwiftTests/DictionaryExtensionsTests.swift @@ -0,0 +1,368 @@ +// +// DictionaryExtensionsTests.swift +// ExSwift +// +// Created by pNre on 04/06/14. +// Copyright (c) 2014 pNre. All rights reserved. +// + +import Quick +import Nimble + +class DictionaryExtensionsSpec: QuickSpec { + + var dictionary: [String: Int] = [String: Int]() + + override func spec() { + + beforeEach { () -> () in + + self.dictionary = [ + "A": 1, + "B": 2, + "C": 3 + ] + + } + + /** + * Dictionary.has + */ + it("has") { + + expect(self.dictionary.has("A")).to(beTrue()) + expect(self.dictionary.has("Z")).to(beFalse()) + + } + + /** + * Dictionary.mapValues + */ + it("mapValues") { + + let mapped = self.dictionary.mapValues({ key, value -> Int in + return value + 1 + }) + + expect(mapped) == ["A": 2, "B": 3, "C": 4] + + } + + /** + * Dictionary.map + */ + it("map") { + + let mapped = self.dictionary.map({ key, value -> (String, Int) in return (key + "A", value + 1) }) + + expect(mapped) == ["AA": 2, "BA": 3, "CA": 4] + + } + + /** + * Dictionary.mapFilterValues + */ + it("mapFilterValues") { + + let result = self.dictionary.mapFilterValues { (key, value) -> Int? in + if key == "B" { + return nil + } + + return value + 1 + } + + expect(result) == ["A": 2, "C": 4] + + expect(self.dictionary.mapFilterValues { (key, value) -> Int? in nil }) == [String: Int]() + expect(self.dictionary.mapFilterValues { (key, value) -> Int? in value }) == self.dictionary + + } + + /** + * Dictionary.mapFilter + */ + it("mapFilter") { + + let mapped = self.dictionary.mapFilter({ key, value -> (String, String)? in + if key == "C" { + return ("D", key) + } + + return nil + }) + + expect(mapped) == ["D": "C"] + + expect(self.dictionary.mapFilter { (key, value) -> (String, String)? in nil }) == [String: String]() + expect(self.dictionary.mapFilter { (key, value) -> (String, Int)? in (key, value) }) == self.dictionary + + } + + /** + * Dictionary.filter + */ + it("filter") { + + expect(self.dictionary.filter { key, _ in return key != "A" }) == ["B": 2, "C": 3] + + expect(self.dictionary.filter { key, _ in return false }) == [String: Int]() + expect(self.dictionary.filter { key, _ in return true }) == self.dictionary + + } + + /** + * Dictionary.countWhere + */ + it("countWhere") { + + expect(self.dictionary.countWhere { key, _ in return key != "A" }) == 2 + + expect(self.dictionary.countWhere { key, _ in return false }) == 0 + expect(self.dictionary.countWhere { key, _ in return true }) == 3 + + } + + /** + * Dictionary.any + */ + it("any") { + + expect(self.dictionary.any { _, value -> Bool in return value % 2 == 0 }).to(beTrue()) + + expect(self.dictionary.any { _, value -> Bool in return value >= 0 }).to(beTrue()) + + expect(self.dictionary.any { _, value -> Bool in return value < 0 }).to(beFalse()) + + } + + /** + * Dictionary.all + */ + it("all") { + + expect(self.dictionary.all { _, value -> Bool in return value % 2 == 0 }).to(beFalse()) + + expect(self.dictionary.all { _, value -> Bool in return value >= 0 }).to(beTrue()) + + expect(self.dictionary.all { _, value -> Bool in return value < 0 }).to(beFalse()) + + } + + /** + * Dictionary.shift + */ + it("shift") { + + let unshifted = self.dictionary + let (key, value) = self.dictionary.shift()! + + expect(unshifted.keys.array).to(contain(key)) + expect(self.dictionary.keys.array).toNot(contain(key)) + + expect(unshifted[key]) == value + expect(self.dictionary[key]).to(beNil()) + + expect(unshifted.values.array).to(contain(value)) + expect(self.dictionary.values.array).toNot(contain(value)) + + } + + /** + * Dictionary.pick + */ + it("pick") { + + let pick1 = self.dictionary.pick(["A", "C"]) + + expect(pick1) == ["A": 1, "C": 3] + + let pick2 = self.dictionary.pick("A", "C") + + expect(pick2) == pick1 + + expect(self.dictionary.pick(["K"])) == [:] + expect(self.dictionary.pick([])) == [:] + expect(self.dictionary.pick()) == [:] + + } + + /** + * Dictionary.groupBy + */ + it("groupBy") { + + let grouped = self.dictionary.groupBy { _, value -> Bool in + return (value % 2 == 0) + } + + expect(grouped.keys.array - [false, true]).to(beEmpty()) + expect(grouped[true]) == [2] + + expect(grouped[false]!.count) == 2 + expect(grouped[false]! - [1, 3]).to(beEmpty()) + + } + + /** + * Dictionary.countBy + */ + it("countBy") { + + let grouped = self.dictionary.countBy { _, value -> Bool in + return (value % 2 == 0) + } + + expect(grouped.keys.array - [false, true]).to(beEmpty()) + expect(grouped[true]) == 1 + expect(grouped[false]) == 2 + + } + + /** + * Dictionary.reduce + */ + it("reduce") { + + let reduced1 = self.dictionary.reduce([Int: String](), combine: { + (var initial: [Int: String], couple: (String, Int)) in + initial.updateValue(couple.0, forKey: couple.1) + return initial + }) + + expect(reduced1) == [2: "B", 3: "C", 1: "A"] + + let reduced2 = self.dictionary.reduce(0, combine: { (initial: Int, couple: (String, Int)) in + return initial + couple.1 + }) + + expect(reduced2) == self.dictionary.values.array.reduce(+) + + } + + /** + * Dictionary.difference + */ + describe("difference") { + + let dictionary1 = [ "A": 1, "B": 2, "C": 3 ] + let dictionary2 = [ "A": 1 ] + let dictionary3 = [ "B": 2, "C": 3 ] + + it("operator") { + + expect(self.dictionary - dictionary1) == [:] + expect(self.dictionary - dictionary2) == [ "B": 2, "C": 3 ] + expect(self.dictionary - dictionary3) == [ "A": 1 ] + + expect(dictionary2 - dictionary3) != (dictionary3 - dictionary2) + + expect(dictionary2 - dictionary3) == dictionary2 + expect(dictionary2 - [:]) == dictionary2 + + } + + it("method") { + + expect(self.dictionary.difference(dictionary1)) == [:] + expect(self.dictionary.difference(dictionary2)) == [ "B": 2, "C": 3 ] + expect(self.dictionary.difference(dictionary3)) == [ "A": 1 ] + + expect(dictionary2.difference(dictionary3)) != dictionary3.difference(dictionary2) + + expect(dictionary2.difference(dictionary3)) == dictionary2 + expect(dictionary2.difference([:])) == dictionary2 + + } + + } + + /** + * Dictionary.union + */ + describe("union") { + + let dictionary1 = [ "A": 1, "B": 2, "C": 3 ] + let dictionary2 = [ "A": 1 ] + let dictionary3 = [ "B": 2, "C": 3 ] + + it("operator") { + + expect(self.dictionary | dictionary1) == self.dictionary + expect(self.dictionary | dictionary2) == self.dictionary + expect(self.dictionary | dictionary3) == self.dictionary + + expect(dictionary2 | dictionary3) == (dictionary3 | dictionary2) + expect(dictionary2 | dictionary3) == self.dictionary + + expect(dictionary1 | [:]) == dictionary1 + + } + + it("method") { + + expect(self.dictionary.union(dictionary1)) == self.dictionary + expect(self.dictionary.union(dictionary2)) == self.dictionary + expect(self.dictionary.union(dictionary3)) == self.dictionary + + expect(dictionary2.union(dictionary3)) == dictionary3.union(dictionary2) + expect(dictionary2.union(dictionary3)) == self.dictionary + + expect(dictionary1.union([:])) == dictionary1 + + } + + } + + /** + * Dictionary.intersection + */ + describe("intersection") { + + let dictionary1 = [ "A": 1, "B": 2, "C": 3 ] + let dictionary2 = [ "A": 1 ] + let dictionary3 = [ "B": 2, "C": 3 ] + + it("operator") { + + expect(self.dictionary & dictionary1) == self.dictionary + expect(self.dictionary & dictionary2) == dictionary2 + expect(self.dictionary & dictionary3) == dictionary3 + + expect(dictionary2 & dictionary3) == (dictionary3 & dictionary2) + expect(dictionary2 & dictionary3) == [String: Int]() + + expect(dictionary1 & [:]) == [:] + + } + + it("method") { + + expect(self.dictionary.intersection(dictionary1)) == self.dictionary + expect(self.dictionary.intersection(dictionary2)) == dictionary2 + expect(self.dictionary.intersection(dictionary3)) == dictionary3 + + expect(dictionary2.intersection(dictionary3)) == dictionary3.intersection(dictionary2) + expect(dictionary2.intersection(dictionary3)) == [String: Int]() + + expect(dictionary1.intersection([:])) == [String: Int]() + + } + + } + + /** + * Dictionary.toArray + */ + it("toArray") { + + expect(self.dictionary.toArray({ (key, value) -> String in key })) == self.dictionary.keys.array + expect(self.dictionary.toArray({ (key, value) -> Int in value })) == self.dictionary.values.array + + expect(self.dictionary.toArray({ (key, value) -> Bool in false })) == [false, false, false] + + } + + } + +} diff --git a/ExSwiftTests/DoubleExtensionsTests.swift b/ExSwiftTests/DoubleExtensionsTests.swift new file mode 100644 index 0000000..2da285c --- /dev/null +++ b/ExSwiftTests/DoubleExtensionsTests.swift @@ -0,0 +1,125 @@ +// +// DoubleExtensionsTests.swift +// ExSwift +// +// Created by pNre on 10/07/14. +// Copyright (c) 2014 pNre. All rights reserved. +// + +import Quick +import Nimble + +class DoubleExtensionsSpec: QuickSpec { + + override func spec() { + + /** + * Double.abs + */ + it("abs") { + + expect(Double(0).abs()) == Double(0) + + expect(Double(-1).abs()).to(beCloseTo(1, within: 0.001)) + expect(Double(1).abs()).to(beCloseTo(1, within: 0.001)) + + expect(Double(-111.2).abs()).to(beCloseTo(111.2, within: 0.001)) + expect(Double(111.2).abs()).to(beCloseTo(111.2, within: 0.001)) + + } + + /** + * Double.sqrt + */ + it("sqrt") { + + expect(Double(0).sqrt()) == Double(0) + + expect(Double(4).sqrt()).to(beCloseTo(2, within: 0.001)) + expect(Double(111.2).sqrt()).to(beCloseTo(sqrt(111.2), within: 0.001)) + + expect(isnan(Double(-10).sqrt())).to(beTrue()) + + } + + /** + * Double.floor + */ + it("floor") { + + expect(Double(0).floor()) == Double(0) + + expect(Double(4.99999999).floor()).to(beCloseTo(4, within: 0.001)) + expect(Double(4.001).floor()).to(beCloseTo(4, within: 0.001)) + expect(Double(4.5).floor()).to(beCloseTo(4, within: 0.001)) + + expect(Double(-4.99999999).floor()).to(beCloseTo(-5, within: 0.001)) + expect(Double(-4.001).floor()).to(beCloseTo(-5, within: 0.001)) + expect(Double(-4.5).floor()).to(beCloseTo(-5, within: 0.001)) + + } + + /** + * Double.ceil + */ + it("ceil") { + + expect(Double(0).ceil()) == Double(0) + + expect(Double(4.99999999).ceil()).to(beCloseTo(5, within: 0.001)) + expect(Double(4.001).ceil()).to(beCloseTo(5, within: 0.001)) + expect(Double(4.5).ceil()).to(beCloseTo(5, within: 0.001)) + + expect(Double(-4.99999999).ceil()).to(beCloseTo(-4, within: 0.001)) + expect(Double(-4.001).ceil()).to(beCloseTo(-4, within: 0.001)) + expect(Double(-4.5).ceil()).to(beCloseTo(-4, within: 0.001)) + + } + + /** + * Double.round + */ + it("round") { + + expect(Double(0).round()) == Double(0) + + expect(Double(4.99999999).round()).to(beCloseTo(5, within: 0.001)) + expect(Double(4.001).round()).to(beCloseTo(4, within: 0.001)) + expect(Double(4.5).round()).to(beCloseTo(5, within: 0.001)) + + expect(Double(4.3).round()).to(beCloseTo(4, within: 0.001)) + expect(Double(4.7).round()).to(beCloseTo(5, within: 0.001)) + + expect(Double(-4.99999999).round()).to(beCloseTo(-5, within: 0.001)) + expect(Double(-4.001).round()).to(beCloseTo(-4, within: 0.001)) + expect(Double(-4.5).round()).to(beCloseTo(-5, within: 0.001)) + + } + + /** + * Double.roundToNearest + */ + it("roundToNearest") { + + expect(2.5.roundToNearest(0.3)).to(beCloseTo(2.4, within: 0.01)) + expect(0.roundToNearest(0.3)).to(beCloseTo(0.0, within: 0.01)) + expect(4.0.roundToNearest(2)).to(beCloseTo(4.0, within: 0.01)) + expect(10.0.roundToNearest(3)).to(beCloseTo(9.0, within: 0.01)) + expect(-2.0.roundToNearest(3)).to(beCloseTo(-3.0, within: 0.01)) + + } + + /** + * Double.clamp + */ + it("clamp") { + + expect(Double(0.25).clamp(0, 0.5)).to(beCloseTo(0.25, within: 0.01)) + expect(Double(2).clamp(0, 0.5)).to(beCloseTo(0.5, within: 0.01)) + expect(Double(-2).clamp(0, 0.5)).to(beCloseTo(0, within: 0.01)) + + } + + } + +} diff --git a/ExSwiftTests/ExSwiftDoubleTests.swift b/ExSwiftTests/ExSwiftDoubleTests.swift deleted file mode 100644 index a953570..0000000 --- a/ExSwiftTests/ExSwiftDoubleTests.swift +++ /dev/null @@ -1,50 +0,0 @@ -// -// ExSwiftDoubleTests.swift -// ExSwift -// -// Created by pNre on 10/07/14. -// Copyright (c) 2014 pNre. All rights reserved. -// - -import XCTest - -class ExSwiftDoubleTests: XCTestCase { - - func testAbs() { - XCTAssertGreaterThan(Double(-1.0).abs(), 0) - } - - func testSqrt() { - XCTAssertEqual(2, Double(4.0).sqrt()) - } - - func testFloor () { - XCTAssertEqual(2, Double(2.9).floor()) - } - - func testCeil () { - XCTAssertEqual(3, Double(2.9).ceil()) - } - - func testRound () { - XCTAssertEqual(3, Double(2.5).round()) - XCTAssertEqual(2, Double(2.4).round()) - } - - func testClamp () { - XCTAssertEqualWithAccuracy(Double(0.25).clamp(0, 0.5), Double(0.25), 0.01) - XCTAssertEqualWithAccuracy(Double(2).clamp(0, 0.5), Double(0.5), 0.01) - XCTAssertEqualWithAccuracy(Double(-2).clamp(0, 0.5), Double(0), 0.01) - } - - func testRandom() { - } - - func testRoundToNearest () { - XCTAssertEqualWithAccuracy(2.5.roundToNearest(0.3), 2.4, 0.01) - XCTAssertEqualWithAccuracy(0.roundToNearest(0.3), 0.0, 0.01) - XCTAssertEqualWithAccuracy(4.0.roundToNearest(2), 4.0, 0.01) - XCTAssertEqualWithAccuracy(10.0.roundToNearest(3), 9.0, 0.01) - XCTAssertEqualWithAccuracy(-2.0.roundToNearest(3), -3.0, 0.01) - } -} diff --git a/ExSwiftTests/ExSwiftFloatTests.swift b/ExSwiftTests/ExSwiftFloatTests.swift deleted file mode 100644 index 1f705eb..0000000 --- a/ExSwiftTests/ExSwiftFloatTests.swift +++ /dev/null @@ -1,43 +0,0 @@ -// -// ExSwiftFloatTests.swift -// ExSwift -// -// Created by pNre on 04/06/14. -// Copyright (c) 2014 pNre. All rights reserved. -// - -import XCTest - -class ExSwiftFloatTests: XCTestCase { - - func testAbs() { - XCTAssertGreaterThan(Float(-1.0).abs(), Float(0)) - } - - func testSqrt() { - XCTAssertEqual(Float(2), Float(4.0).sqrt()) - } - - func testFloor () { - XCTAssertEqual(Float(2), Float(2.9).floor()) - } - - func testCeil () { - XCTAssertEqual(Float(3), Float(2.9).ceil()) - } - - func testRound () { - XCTAssertEqual(Float(3), Float(2.5).round()) - XCTAssertEqual(Float(2), Float(2.4).round()) - } - - func testClamp () { - XCTAssertEqualWithAccuracy(Float(0.25).clamp(0, 0.5), Float(0.25), 0.01) - XCTAssertEqualWithAccuracy(Float(2).clamp(0, 0.5), Float(0.5), 0.01) - XCTAssertEqualWithAccuracy(Float(-2).clamp(0, 0.5), Float(0), 0.01) - } - - func testRandom() { - } - -} diff --git a/ExSwiftTests/ExSwiftIntTests.swift b/ExSwiftTests/ExSwiftIntTests.swift deleted file mode 100644 index fb53e1a..0000000 --- a/ExSwiftTests/ExSwiftIntTests.swift +++ /dev/null @@ -1,150 +0,0 @@ -// -// ExSwiftIntTests.swift -// ExSwift -// -// Created by pNre on 03/06/14. -// Copyright (c) 2014 pNre. All rights reserved. -// - -import XCTest - -class ExSwiftIntTests: XCTestCase { - - func testTimes() { - var count = 0 - - 5.times({ - count++ - }) - - XCTAssertEqual(5, count) - - 0.times({ - count++ - }) - - XCTAssertEqual(5, count) - } - - func testTimesWithIndex() { - - var indexes = Array() - - 5.times({ - indexes.append($0) - }) - - XCTAssertEqual(indexes, [0, 1, 2, 3, 4]) - - } - - func testEven() { - - XCTAssertFalse((-1).isEven()) - XCTAssertFalse(3.isEven()) - XCTAssertTrue(4.isEven()) - XCTAssertTrue((-2).isEven()) - - } - - func testOdd() { - - XCTAssertTrue((-1).isOdd()) - XCTAssertTrue(3.isOdd()) - XCTAssertFalse(4.isOdd()) - XCTAssertFalse((-2).isOdd()) - - } - - func testRandom() { - - 10.times({ - var a = Int.random(min: 5, max: 10) - XCTAssertGreaterThanOrEqual(a, 5) - XCTAssertLessThanOrEqual(a, 10) - }) - - } - - func testUpTo() { - var result = Array() - - 5.upTo(10, function: { result.append($0) }) - - XCTAssertEqual(result, Array(5...10)) - } - - func testDownTo() { - - var result = Array() - - 3.downTo(0, function: { result.append($0) }) - - XCTAssertEqual(result, [3, 2, 1, 0]) - - } - - func testClamp () { - XCTAssertEqual(5.clamp(0...4), 4) - XCTAssertEqual(3.clamp(0...4), 3) - XCTAssertEqual(1.clamp(2...4), 2) - } - - func testIn () { - XCTAssertTrue(2.isIn(0..<3)) - XCTAssertFalse(2.isIn(0..<3, strict: true)) - - XCTAssertTrue(0.isIn(0..<3)) - XCTAssertFalse(0.isIn(0..<3, strict: true)) - - XCTAssertTrue(2.isIn(0...2)) - XCTAssertFalse(2.isIn(0...2, strict: true)) - } - - func testExplode () { - let result = 362.digits() - XCTAssertEqual(result, [3, 6, 2]) - } - - func testGCD () { - XCTAssertEqual(3, 3.gcd(6)) - XCTAssertEqual(3, 6.gcd(3)) - XCTAssertEqual(2, 6124.gcd(342)) - XCTAssertEqual(2, 342.gcd(6124)) - } - - func testAbs () { - XCTAssertEqual(1, (-1).abs()) - } - - func testLCM () { - XCTAssertEqual(12, 3.lcm(4)) - XCTAssertEqual(12, 4.lcm(3)) - } - - func testYears () { - XCTAssertEqual(94608000, 3.year) - XCTAssertEqual(31536000, 1.years) - } - - func testDays () { - XCTAssertEqual(1728000, 20.day) - XCTAssertEqual(86400, 1.days) - } - - func testHours () { - XCTAssertEqual(72000, 20.hour) - XCTAssertEqual(10800, 3.hours) - } - - func testMinutes () { - XCTAssertEqual(60, 1.minute) - XCTAssertEqual(3600, 60.minutes) - } - - func testSeconds () { - XCTAssertEqual(20, 20.second) - XCTAssertEqual(-1, -1.second) - } -} - diff --git a/ExSwiftTests/ExSwiftNSArrayTests.swift b/ExSwiftTests/ExSwiftNSArrayTests.swift deleted file mode 100644 index 05ca80b..0000000 --- a/ExSwiftTests/ExSwiftNSArrayTests.swift +++ /dev/null @@ -1,31 +0,0 @@ -// -// ExSwiftNSArrayTests.swift -// ExSwift -// -// Created by pNre on 10/06/14. -// Copyright (c) 2014 pNre. All rights reserved. -// - -import XCTest - -class ExSwiftNSArrayTests: XCTestCase { - - let array: NSArray = ["A", 10, "B", "C", false] - - func testCast() { - // Any NSNumber is always converted to Bool or Int - XCTAssertEqual(array.cast() as [NSNumber], [10, 0]) - XCTAssertEqual(array.cast() as [NSString], ["A", "B", "C"]) - - XCTAssertEqual(array.cast() as [Int], [10, 0]) - } - - func testFlatten () { - let array = [5, [6, ["A", 7]], 8] - XCTAssertEqual(array.flatten() as [NSNumber], [5, 6, 7, 8]) - XCTAssertEqual(array.flatten() as [Int], [5, 6, 7, 8]) - XCTAssertEqual(array.flatten() as [String], ["A"]) - - XCTAssertEqual(array.flattenAny() as! [NSObject], [5, 6, "A", 7, 8]) - } -} diff --git a/ExSwiftTests/ExSwiftNSDateTests.swift b/ExSwiftTests/ExSwiftNSDateTests.swift deleted file mode 100644 index c5e1592..0000000 --- a/ExSwiftTests/ExSwiftNSDateTests.swift +++ /dev/null @@ -1,240 +0,0 @@ -// -// ExSfitNSDateTests.swift -// ExSwift -// -// Created by Piergiuseppe Longo on 23/11/14. -// Copyright (c) 2014 pNre. All rights reserved. -// - - -import XCTest - -class ExSwiftNSDataTests: XCTestCase { - - let dateFormatter = NSDateFormatter() - var startDate: NSDate? - - override func setUp() { - super.setUp() - dateFormatter.dateFormat = "dd/MM/yyyy HH:mm:ss" - startDate = dateFormatter.dateFromString("30/11/1988 00:00:00") - } - - // MARK: NSDate Manipulation - - func testAddSeconds() { - var expectedDate = dateFormatter.dateFromString("30/11/1988 00:00:42") - var result = startDate?.addSeconds(42) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - result = startDate?.add(seconds:42) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - - expectedDate = dateFormatter.dateFromString("29/11/1988 23:59:18") - result = startDate?.addSeconds(-42) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - result = startDate?.add(seconds:-42) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - } - - func testAddMinutes() { - var expectedDate = dateFormatter.dateFromString("30/11/1988 00:42:00") - var result = startDate?.addMinutes(42) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - result = startDate?.add(minutes:42) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - - expectedDate = dateFormatter.dateFromString("29/11/1988 23:18:00") - result = startDate?.addMinutes(-42) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - result = startDate?.add(minutes:-42) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - } - - func testAddHours() { - var expectedDate = dateFormatter.dateFromString("01/12/1988 18:00:00") - var result = startDate?.addHours(42) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - result = startDate?.add(hours:42) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - - expectedDate = dateFormatter.dateFromString("28/11/1988 06:00:00") - result = startDate?.addHours(-42) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - result = startDate?.add(hours:-42) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - - - } - - func testAddDays() { - var expectedDate = dateFormatter.dateFromString("02/12/1988 00:00:00") - var result = startDate?.addDays(2) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - result = startDate?.add(days:2) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - - expectedDate = dateFormatter.dateFromString("19/10/1988 00:00:00") - result = startDate?.addDays(-42) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - result = startDate?.add(days:-42) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - - } - - func testAddWeeks() { - var expectedDate = dateFormatter.dateFromString("7/12/1988 00:00:00") - var result = startDate?.addWeeks(1) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - result = startDate?.add(weeks:1) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - - expectedDate = dateFormatter.dateFromString("23/11/1988 00:00:00") - result = startDate?.addWeeks(-1) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - result = startDate?.add(weeks:-1) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - - } - - func testAddMonths() { - var expectedDate = dateFormatter.dateFromString("30/12/1988 00:00:00") - var result = startDate?.addMonths(1) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - result = startDate?.add(months:1) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - - expectedDate = dateFormatter.dateFromString("30/10/1988 00:00:00") - result = startDate?.addMonths(-1) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - result = startDate?.add(months:-1) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - - } - - func testAddYears() { - var expectedDate = dateFormatter.dateFromString("30/11/1989 00:00:00") - var result = startDate?.addYears(1) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - result = startDate?.add(years:1) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - - expectedDate = dateFormatter.dateFromString("30/11/1987 00:00:00") - result = startDate?.addYears(-1) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - result = startDate?.add(years:-1) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - - } - - func testAdd(){ - var expectedDate = dateFormatter.dateFromString("10/01/1990 18:42:42") - var result = startDate?.addMonths(1) - result = startDate?.add(seconds: 42, minutes: 42, hours: 42, days: 2, weeks: 1 , months: 1, years: 1) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - - expectedDate = dateFormatter.dateFromString("20/10/1987 22:17:18") - result = startDate?.add(seconds: -42, minutes: -42, hours: -1, days: -2, weeks: -1 , months: -1, years: -1) - XCTAssertEqual(expectedDate!, result!, "Date mismatch") - - } - - // MARK: Date comparison - - func testIsAfter(){ - var date = NSDate() - var futureDate = date.addSeconds(42) - var pastDate = date.addSeconds(-42) - XCTAssertTrue(futureDate.isAfter(date), "Future date should be in the future") - XCTAssertFalse(date.isAfter(date), "Past date should be in the past") - XCTAssertFalse(pastDate.isAfter(date), "Past date should be in the past") - } - - func testIsBefore(){ - var date = NSDate() - var futureDate = date.addSeconds(42) - var pastDate = date.addSeconds(-42) - XCTAssertFalse(futureDate.isBefore(date), "Future date should be in the future") - XCTAssertTrue(pastDate.isBefore(date), "Past date should be in the past") - XCTAssertFalse(date.isAfter(date), "Past date should be in the past") - - } - - // MARK: Getter - - func testGetter() { - XCTAssertEqual(1988, startDate!.year, "Year Mismatch") - XCTAssertEqual(11, startDate!.month, "Month Mismatch") - XCTAssertEqual(30, startDate!.days, "Day Mismatch") - XCTAssertEqual(0, startDate!.hours, "Hours Mismatch") - XCTAssertEqual(0, startDate!.minutes, "Minutes Mismatch") - XCTAssertEqual(0, startDate!.seconds, "Seconds Mismatch") - XCTAssertEqual(4, startDate!.weekday, "Weekmonth Mismatch") - XCTAssertEqual(5, startDate!.weekMonth, "Weekmonth Mismatch") - } - - // MARK: Comparable - - func testSorting () { - var firstDate = startDate!.addSeconds(0) - var secondDate = startDate!.addSeconds(42) - var thirdDate = startDate!.addSeconds(-42) - var fourthDate = startDate!.addSeconds(-84) - var fifthDate = startDate!.addSeconds(84) - - var dates : [NSDate] = [thirdDate, secondDate, firstDate, fourthDate, fifthDate] - - let expected : [NSDate] = [fifthDate, secondDate, firstDate, thirdDate, fourthDate] - - let expectedReverded = expected.reverse() - - for i in 0 ... 42 { - dates.shuffle() - - dates.sort( { $0 > $1 } ) - XCTAssertEqual(expected, dates, "Sort mismatch") - - dates.sort( { $0 < $1 } ) - XCTAssertEqual(expectedReverded, dates, "Sort mismatch") - } - } - - func testComparable(){ - var date = startDate!.addSeconds(-42) - var anotherDate = startDate!.addSeconds(42) - let shouldBeTheSameDate = NSDate(timeInterval: 0, sinceDate: startDate!) - - - XCTAssertTrue(startDate > date, "Date should be greater") - XCTAssertFalse(startDate > anotherDate, "Date shouldn't be greater") - XCTAssertFalse(startDate > shouldBeTheSameDate, "Date shouldn't be greater") - - XCTAssertTrue(startDate < anotherDate, "Date should be lower") - XCTAssertFalse(startDate < date, "Date shouldn't be lower") - XCTAssertFalse(startDate < shouldBeTheSameDate, "Date shouldn't be lower") - - XCTAssertTrue(startDate >= shouldBeTheSameDate, "Date should be greater or equal") - XCTAssertTrue(startDate >= date, "Date should be greater or equal") - XCTAssertFalse(startDate >= anotherDate, "Date shouldn't be greater or equal") - - XCTAssertTrue(startDate <= shouldBeTheSameDate, "Date should be lower or equal") - XCTAssertTrue(startDate < anotherDate, "Date should be lower") - XCTAssertFalse(startDate <= date, "Date shouldn't be greater or equal") - - XCTAssertFalse(date == startDate, "Date should mismatch") - XCTAssertFalse(anotherDate == startDate, "Date should mismatch") - XCTAssertTrue(shouldBeTheSameDate == startDate, "Date shouldn't mismatch") - } - - func testArithmetic() { - let date = NSDate() as NSDate - XCTAssertTrue(date.timeIntervalSinceDate(date - 1.hour) == 1.hour) - XCTAssertTrue(date.timeIntervalSinceDate(date + 1.hour) == -1.hour) - - var otherDate = date - otherDate -= 1.minute - XCTAssertFalse(otherDate === date) - XCTAssertTrue(date.timeIntervalSinceDate(otherDate) == 1.minute) - otherDate += 1.hour - XCTAssertTrue(date.timeIntervalSinceDate(otherDate) == 1.minute - 1.hour) - } -} diff --git a/ExSwiftTests/ExSwiftRangeTests.swift b/ExSwiftTests/ExSwiftRangeTests.swift deleted file mode 100644 index a3b00cd..0000000 --- a/ExSwiftTests/ExSwiftRangeTests.swift +++ /dev/null @@ -1,58 +0,0 @@ -// -// ExSwiftRangeTests.swift -// ExSwift -// -// Created by pNre on 04/06/14. -// Copyright (c) 2014 pNre. All rights reserved. -// - -import XCTest - -class ExSwiftRangeTests: XCTestCase { - - func testTimes() { - var count: Int = 0 - - (2..<4).times({ - count++ - return - }) - - XCTAssertEqual(count, 2) - - count = 0 - - (2...4).times({ - count++ - return - }) - - XCTAssertEqual(count, 3) - } - - func testEach() { - - var items = Array() - - (0..<2).each({ - items.append($0) - }) - - XCTAssertEqual(items, [0, 1]) - - (0..<0).each({ (current: Int) in - XCTFail() - return - }) - - items.removeAll(keepCapacity: false) - - for i in 0..5 { - items.append(i) - } - - XCTAssertEqual(items, [0, 1, 2, 3, 4]) - - } - -} diff --git a/ExSwiftTests/ExSwiftSequenceTests.swift b/ExSwiftTests/ExSwiftSequenceTests.swift deleted file mode 100644 index 7ce5de5..0000000 --- a/ExSwiftTests/ExSwiftSequenceTests.swift +++ /dev/null @@ -1,128 +0,0 @@ -// -// ExSwiftSequenceTests.swift -// ExSwift -// -// Created by Colin Eberhardt on 24/06/2014. -// Copyright (c) 2014 pNre. All rights reserved. -// - -import XCTest - -class ExtensionsSequenceTests: XCTestCase { - - var sequence = 1...5 - var emptySequence = 1..<1 - - func testFirst () { - var first = SequenceOf(sequence).first() - XCTAssertEqual(first!, 1) - } - - func testFirstEmotySequence () { - var first = SequenceOf(emptySequence).first() - XCTAssertNil(first) - } - - func testSkip () { - var skipped = SequenceOf(sequence).skip(2) - XCTAssertEqual(Array(skipped), [3, 4, 5]) - } - - func testSkipBeyondEnd () { - var skipped = SequenceOf(sequence).skip(8) - XCTAssertEqual(Array(skipped), []) - } - - func testSkipWhile () { - var skipped = SequenceOf(sequence).skipWhile { $0 < 3 } - XCTAssertEqual(Array(skipped), [3, 4, 5]) - } - - func testSkipWhileBeyondEnd () { - var skipped = SequenceOf(sequence).skipWhile { $0 < 20 } - XCTAssertEqual(Array(skipped), []) - } - - func testContains () { - XCTAssertTrue(SequenceOf(sequence).contains(1)) - XCTAssertFalse(SequenceOf(sequence).contains(56)) - } - - func testTake () { - var take = SequenceOf(sequence).take(2) - XCTAssertEqual(Array(take), [1, 2]) - } - - func testTakeBeyondSequenceEnd () { - var take = SequenceOf(sequence).take(20) - XCTAssertEqual(Array(take), [1, 2, 3, 4, 5]) - } - - func testTakeWhile () { - var take = SequenceOf(sequence).takeWhile { $0 != 3 } - XCTAssertEqual(Array(take), [1, 2]) - } - - func testTakeWhileConditionNeverTrue () { - var take = SequenceOf(sequence).takeWhile { $0 == 7 } - XCTAssertEqual(Array(take), []) - } - - func testTakeWhileConditionNotMet () { - var take = SequenceOf(sequence).takeWhile { $0 != 7 } - XCTAssertEqual(Array(take), [1, 2, 3, 4, 5]) - } - - func testIndexOf () { - XCTAssertEqual(SequenceOf(sequence).indexOf(2)!, 1) - XCTAssertNil(SequenceOf(sequence).indexOf(77)) - } - - func testGet () { - XCTAssertEqual(SequenceOf(sequence).get(3)!, 3) - XCTAssertNil(SequenceOf(sequence).get(22)) - } - - func testGetRange () { - var subSequence = SequenceOf(sequence).get(1..<3) - XCTAssertEqual(Array(subSequence), [2, 3]) - - subSequence = SequenceOf(sequence).get(0..<0) - XCTAssertEqual(Array(subSequence), []) - } - - func testGetRangeOutOfBounds () { - var subSequence = SequenceOf(sequence).get(10..<15) - XCTAssertEqual(Array(subSequence), []) - } - - func testAny () { - XCTAssertTrue(SequenceOf(sequence).any { $0 == 1 }) - XCTAssertFalse(SequenceOf(sequence).any { $0 == 77 }) - } - - func testFilter () { - var evens = SequenceOf(sequence).filter { $0 % 2 == 0 } - XCTAssertEqual(Array(evens), [2, 4]) - - var odds = SequenceOf(sequence).filter { $0 % 2 == 1 } - XCTAssertEqual(Array(odds), [1, 3, 5]) - - var all = SequenceOf(sequence).filter { $0 < 10 } - XCTAssertEqual(Array(all), [1, 2, 3, 4, 5]) - - var none = SequenceOf(sequence).filter { $0 > 10 } - XCTAssertEqual(Array(none), []) - } - - func testReject () { - var rejected = SequenceOf(sequence).reject { $0 == 3 } - XCTAssertEqual(Array(rejected), [1, 2, 4, 5]) - - rejected = SequenceOf(sequence).reject { $0 == 1 } - XCTAssertEqual(Array(rejected), [2, 3, 4, 5]) - - rejected = SequenceOf(sequence).reject { $0 == 10 } - XCTAssertEqual(Array(rejected), [1, 2, 3, 4, 5]) - } -} \ No newline at end of file diff --git a/ExSwiftTests/ExSwiftStringTests.swift b/ExSwiftTests/ExSwiftStringTests.swift deleted file mode 100644 index 70bfe30..0000000 --- a/ExSwiftTests/ExSwiftStringTests.swift +++ /dev/null @@ -1,237 +0,0 @@ -// -// ExSwiftStringTests.swift -// ExSwift -// -// Created by ExSwift on 04/06/14. -// Copyright (c) 2014 pNre. All rights reserved. -// - -import XCTest - -class ExSwiftStringTests: XCTestCase { - - func testLength() { - XCTAssertEqual(0, "".length) - XCTAssertEqual(1, "A".length) - XCTAssertEqual(1, "😱".length) - XCTAssertEqual(1, "∞".length) - XCTAssertEqual(3, "∞aA".length) - } - - func testSubscript() { - let string = "βˆ†TestπŸ˜—" - - XCTAssertEqual("βˆ†", string[0]!) - XCTAssertEqual("T", string[1]!) - XCTAssertEqual("πŸ˜—", string[string.length - 1]!) - XCTAssertEqual("TestπŸ˜—", string[1..<6]!) - - if let s = "hello"[0] { - XCTAssertEqual(s, "h") - } else { - XCTFail("string[0]") - } - - XCTAssertEqual("ABCD"[0, 2], ["A", "C"]) - } - - func testRepeat () { - - XCTAssertEqual("AAA", "A" * 3) - - } - - func testExplode () { - - let string = "A B C" - XCTAssertEqual(string.explode(" "), ["A", "B", "C"]) - - } - - func testRandom () { - - XCTAssertLessThanOrEqual(String.random().length, 16) - XCTAssertEqual(String.random(length: 12).length, 12) - - } - - func testAt () { - let array1 = "ABCD".at(0, 2) - XCTAssertEqual(array1, ["A", "C"]) - } - - func testMatchingOperators () { - // String - let string = "ABcd" - - XCTAssertTrue(string =~ "^A") - - XCTAssertTrue(string =~ (pattern: "D$", ignoreCase: true)) - XCTAssertFalse(string =~ "D$") - - // String[] all - let strings = [string, string, string] - - XCTAssertTrue(strings =~ "^A") - - XCTAssertTrue(strings =~ (pattern: "D$", ignoreCase: true)) - XCTAssertFalse(strings =~ "D$") - - // String[] any - let strings_2 = [string, "BC", "DE"] - - XCTAssertTrue(strings |~ "^A") - - XCTAssertTrue(strings |~ (pattern: "D$", ignoreCase: true)) - XCTAssertFalse(strings |~ "D$") - - } - - func testMatches () { - let string = "AB[31]" - - let matches = string.matches("\\d+")! - let range = matches[0].rangeAtIndex(0) - - let substringRange = range.location..<(range.location + range.length) - - XCTAssertEqual(string[substringRange]!, "31") - XCTAssertTrue(string.matches("N")!.isEmpty) - } - - func testCapitalized () { - XCTAssertEqual("".capitalized, "") - XCTAssertEqual("abcdef".capitalized, "Abcdef") - XCTAssertEqual("Abcdef".capitalized, "Abcdef") - } - - func testInsert () { - XCTAssertEqual("abcdef".insert(10, "X"), "abcdefX") - XCTAssertEqual("abcdef".insert(3, "X"), "abcXdef") - } - - func testTrimmed () { - XCTAssertEqual("t e".trimmed(), "t e") - XCTAssertEqual(" AB".trimmed(), "AB") - XCTAssertEqual("\n ABC ".trimmed(), "ABC") - XCTAssertEqual("".trimmed(), "") - XCTAssertEqual(" \t\n\r".trimmed(), "") - } - - func testLTrimmed () { - XCTAssertEqual("ab ".ltrimmed(), "ab ") - XCTAssertEqual("ab".ltrimmed(), "ab") - XCTAssertEqual(" AB".ltrimmed(), "AB") - XCTAssertEqual("\n ABC ".ltrimmed(), "ABC ") - XCTAssertEqual("".ltrimmed(), "") - XCTAssertEqual(" \t\n\r".ltrimmed(), "") - } - - func testRTrimmed () { - XCTAssertEqual("t e".rtrimmed(), "t e") - XCTAssertEqual(" AB".rtrimmed(), " AB") - XCTAssertEqual("AB ".rtrimmed(), "AB") - XCTAssertEqual("\n ABC ".rtrimmed(), "\n ABC") - XCTAssertEqual("".rtrimmed(), "") - XCTAssertEqual(" \t\n\r".rtrimmed(), "") - } - - func testLTrimmedForSet () { - XCTAssertEqual("ab ".ltrimmed(NSCharacterSet.alphanumericCharacterSet()), " ") - XCTAssertEqual(" ab".ltrimmed(NSCharacterSet.alphanumericCharacterSet()), " ab") - XCTAssertEqual("ab".ltrimmed(NSCharacterSet.alphanumericCharacterSet()), "") - } - - func testRTrimmedForSet () { - XCTAssertEqual("ab ".rtrimmed(NSCharacterSet.alphanumericCharacterSet()), "ab ") - XCTAssertEqual(" ab".rtrimmed(NSCharacterSet.alphanumericCharacterSet()), " ") - XCTAssertEqual("ab".rtrimmed(NSCharacterSet.alphanumericCharacterSet()), "") - } - - func testToDouble() { - var d : Double = " 7.2 ".toDouble()! - XCTAssertEqual(7.2, d) - - d = "-70.211111".toDouble()! - XCTAssertEqual(-70.211111, d) - - d = "42".toDouble()! - XCTAssertEqual(42, d) - - XCTAssertNil("a772.2".toDouble()) - } - - func testToFloat() { - var f : Float = " 7.2 ".toFloat()! - XCTAssertEqual(Float(7.2), f) - - f = "-70.211111".toFloat()! - XCTAssertEqual(Float(-70.211111), f) - - XCTAssertNil("a772.2".toFloat()) - } - - func testToUInt() { - var u : UInt = " 7 ".toUInt()! - XCTAssertEqual(UInt(7), u) - - XCTAssertNil("a772.2".toUInt()) - XCTAssertNil("-772".toUInt()) - XCTAssertNil("7.5".toUInt()) - } - - func testToBool() { - var b = " TrUe ".toBool()! - XCTAssertEqual(true, b) - b = " yEs ".toBool()! - XCTAssertEqual(true, b) - - b = " FALSE ".toBool()! - XCTAssertEqual(false, b) - b = " nO ".toBool()! - XCTAssertEqual(false, b) - - XCTAssertNil("".toBool()) - XCTAssertNil("jeff".toBool()) - XCTAssertNil("0".toBool()) - } - - func testToDate() { - var d : NSDate = " 2015-08-19 \t ".toDate()! - - var c = NSDateComponents() - c.year = 2015 - c.month = 8 - c.day = 19 - - var gregorian = NSCalendar(identifier:NSGregorianCalendar)! - var expected = gregorian.dateFromComponents(c)! - - XCTAssertEqual(expected, d) - - XCTAssertNil("a772.2".toDate()) - XCTAssertNil("Tuesday".toDate()) - XCTAssertNil("1973-08-19 03:04:55".toDate()) - } - - func testToDateTime() { - var d : NSDate = " 2015-08-19 03:04:34\t ".toDateTime()! - - var c = NSDateComponents() - c.year = 2015 - c.month = 8 - c.day = 19 - c.hour = 3 - c.minute = 4 - c.second = 34 - - var gregorian = NSCalendar(identifier:NSGregorianCalendar)! - var expected = gregorian.dateFromComponents(c)! - - XCTAssertEqual(expected, d) - - XCTAssertNil("a772.2".toDateTime()) - XCTAssertNil("Tuesday".toDateTime()) - XCTAssertNil("1973-08-19".toDateTime()) - } -} diff --git a/ExSwiftTests/ExSwiftTests.swift b/ExSwiftTests/ExSwiftTests.swift index 41ac778..9bd20bd 100644 --- a/ExSwiftTests/ExSwiftTests.swift +++ b/ExSwiftTests/ExSwiftTests.swift @@ -6,106 +6,119 @@ // Copyright (c) 2014 pNre. All rights reserved. // -import XCTest +import Quick +import Nimble -class ExSwiftTests: XCTestCase { - - func testAfter () { - - let f = ExSwift.after(2, function: { () -> Bool in return true }) - - XCTAssertNil(f()) - XCTAssertNil(f()) - XCTAssertTrue(f()!) - - var called = false - - let g = ExSwift.after(2, function: { called = true }) - - g() - g() - g() - - XCTAssertTrue(called) - - } - - func testOnce () { - - // Test execution - var test = false - - let f = Ex.once { test = !test } - - f() - f() - - XCTAssertTrue(test) +class ExSwiftSpec: QuickSpec { + + override func spec() { + + it("after") { + + let f = ExSwift.after(2, function: { () -> Bool in return true }) - // Test return value - var seq = [1, 2, 3, 4].generate() - - let g = Ex.once { Void -> Int in - return seq.next()! + expect(f()).to(beNil()) + expect(f()).to(beNil()) + + expect(f()).to(beTrue()) + + var called = false + let g = ExSwift.after(2, function: { called = true }) + + g() + + expect(called).to(beFalse()) + + g() + + expect(called).to(beFalse()) + + g() + + expect(called).to(beTrue()) + } - XCTAssertEqual(g(), 1) - XCTAssertEqual(g(), 1) + it("once") { + + var seq = [1, 2, 3, 4].generate() + + let g = Ex.once { Void -> Int in + return seq.next()! + } + + expect(g()) == 1 + expect(g()) == 1 + + } - } - - func testPartial () { - let add = { - (params: Int...) -> Int in - return params.reduce(0, combine: { return $0 + $1 }) + it("partial") { + + let add = { (params: Int...) -> Int in + return params.reduce(0, combine: +) + } + + let add5 = ExSwift.partial(add, 5) + + expect(add5(10)) == 15 + expect(add5(1, 2)) == 8 + } - let add5 = ExSwift.partial(add, 5) - - XCTAssertEqual(15, add5(10)) - XCTAssertEqual(8, add5(1, 2)) - } - - func testBind () { - let concat = { - (params: String...) -> String in - return params.implode(" ")! + + it("bind") { + + let concat = { (params: String...) -> String in + return params.implode(" ")! + } + + let helloWorld = ExSwift.bind(concat, "Hello", "World") + + expect(helloWorld()) == "Hello World" + } - - let helloWorld = ExSwift.bind(concat, "Hello", "World") - - XCTAssertEqual(helloWorld(), "Hello World") - } - func testCached () { - var calls = 0 - - // Slow Fibonacci - var fib: ((Int...) -> Int)! - fib = { (params: Int...) -> Int in - let n = params[0] + it("cached") { - calls++ + var calls = 0 - if n <= 1 { - return n + // Slow Fibonacci + var fib: ((Int...) -> Int)! + fib = { (params: Int...) -> Int in + let n = params[0] + + calls++ + + if n <= 1 { + return n + } + return fib(n - 1) + fib(n - 2) } - return fib(n - 1) + fib(n - 2) + + let fibonacci = Ex.cached(fib) + + // This one is computed (fib is called 465 times) + fibonacci(12) + expect(calls) == 465 + + // The results is taken from the cache (fib is not called again) + fibonacci(12) + expect(calls) == 465 + } - - let fibonacci = Ex.cached(fib) - - // This one is computed (fib is called 465 times) - fibonacci(12) - XCTAssertEqual(465, calls) - - // The results is taken from the cache (fib is not called) - fibonacci(12) - XCTAssertEqual(465, calls) + + describe("operators") { + + it("spaceship") { + + expect(4 <=> 5) == -1 + expect(5 <=> 4) == 1 + expect(4 <=> 4) == 0 + + } + + } + } - func testSpaceshipOperator() { - XCTAssertEqual(4 <=> 5, -1) - XCTAssertEqual(5 <=> 4, 1) - XCTAssertEqual(4 <=> 4, 0) - } } + diff --git a/ExSwiftTests/FloatExtensionsTests.swift b/ExSwiftTests/FloatExtensionsTests.swift new file mode 100644 index 0000000..e44a18c --- /dev/null +++ b/ExSwiftTests/FloatExtensionsTests.swift @@ -0,0 +1,125 @@ +// +// FloatExtensionsTests.swift +// ExSwift +// +// Created by pNre on 04/06/14. +// Copyright (c) 2014 pNre. All rights reserved. +// + +import Quick +import Nimble + +class FloatExtensionsSpec: QuickSpec { + + override func spec() { + + /** + * Float.abs + */ + it("abs") { + + expect(Float(0).abs()) == Float(0) + + expect(Float(-1).abs()).to(beCloseTo(1, within: 0.001)) + expect(Float(1).abs()).to(beCloseTo(1, within: 0.001)) + + expect(Float(-111.2).abs()).to(beCloseTo(111.2, within: 0.001)) + expect(Float(111.2).abs()).to(beCloseTo(111.2, within: 0.001)) + + } + + /** + * Float.sqrt + */ + it("sqrt") { + + expect(Float(0).sqrt()) == Float(0) + + expect(Float(4).sqrt()).to(beCloseTo(2, within: 0.001)) + expect(Float(111.2).sqrt()).to(beCloseTo(sqrt(111.2), within: 0.001)) + + expect(isnan(Float(-10).sqrt())).to(beTrue()) + + } + + /** + * Float.floor + */ + it("floor") { + + expect(Float(0).floor()) == Float(0) + + expect(Float(4.99999).floor()).to(beCloseTo(4, within: 0.001)) + expect(Float(4.001).floor()).to(beCloseTo(4, within: 0.001)) + expect(Float(4.5).floor()).to(beCloseTo(4, within: 0.001)) + + expect(Float(-4.99999).floor()).to(beCloseTo(-5, within: 0.001)) + expect(Float(-4.001).floor()).to(beCloseTo(-5, within: 0.001)) + expect(Float(-4.5).floor()).to(beCloseTo(-5, within: 0.001)) + + } + + /** + * Float.ceil + */ + it("ceil") { + + expect(Float(0).ceil()) == Float(0) + + expect(Float(4.99999).ceil()).to(beCloseTo(5, within: 0.001)) + expect(Float(4.001).ceil()).to(beCloseTo(5, within: 0.001)) + expect(Float(4.5).ceil()).to(beCloseTo(5, within: 0.001)) + + expect(Float(-4.99999).ceil()).to(beCloseTo(-4, within: 0.001)) + expect(Float(-4.001).ceil()).to(beCloseTo(-4, within: 0.001)) + expect(Float(-4.5).ceil()).to(beCloseTo(-4, within: 0.001)) + + } + + /** + * Float.round + */ + it("round") { + + expect(Float(0).round()) == Float(0) + + expect(Float(4.99999999).round()).to(beCloseTo(5, within: 0.001)) + expect(Float(4.001).round()).to(beCloseTo(4, within: 0.001)) + expect(Float(4.5).round()).to(beCloseTo(5, within: 0.001)) + + expect(Float(4.3).round()).to(beCloseTo(4, within: 0.001)) + expect(Float(4.7).round()).to(beCloseTo(5, within: 0.001)) + + expect(Float(-4.99999999).round()).to(beCloseTo(-5, within: 0.001)) + expect(Float(-4.001).round()).to(beCloseTo(-4, within: 0.001)) + expect(Float(-4.5).round()).to(beCloseTo(-5, within: 0.001)) + + } + + /** + * Float.roundToNearest + */ + it("roundToNearest") { + + expect(2.5.roundToNearest(0.3)).to(beCloseTo(2.4, within: 0.01)) + expect(0.roundToNearest(0.3)).to(beCloseTo(0.0, within: 0.01)) + expect(4.0.roundToNearest(2)).to(beCloseTo(4.0, within: 0.01)) + expect(10.0.roundToNearest(3)).to(beCloseTo(9.0, within: 0.01)) + expect(-2.0.roundToNearest(3)).to(beCloseTo(-3.0, within: 0.01)) + + } + + /** + * Float.clamp + */ + it("clamp") { + + expect(Float(0.25).clamp(0, 0.5)).to(beCloseTo(0.25, within: 0.01)) + expect(Float(2).clamp(0, 0.5)).to(beCloseTo(0.5, within: 0.01)) + expect(Float(-2).clamp(0, 0.5)).to(beCloseTo(0, within: 0.01)) + + } + + } + +} diff --git a/ExSwiftTests/IntExtensionsTests.swift b/ExSwiftTests/IntExtensionsTests.swift new file mode 100644 index 0000000..09dc176 --- /dev/null +++ b/ExSwiftTests/IntExtensionsTests.swift @@ -0,0 +1,265 @@ +// +// IntExtensionsTests.swift +// ExSwift +// +// Created by pNre on 03/06/14. +// Copyright (c) 2014 pNre. All rights reserved. +// + +import Quick +import Nimble + +class IntExtensionsSpec: QuickSpec { + + override func spec() { + + /** + * Int.times + */ + describe("times") { + + it("iteration") { + + var count = 0 + + 5.times { count++ } + expect(count).to(equal(5)) + + 0.times { count++ } + expect(count).to(equal(5)) + + } + + it("index") { + + var indexes = [Int]() + 5.times(indexes.append) + + expect(indexes) == [0, 1, 2, 3, 4] + + } + + } + + /** + * Int.even + */ + it("even") { + + expect((-1).isEven()).to(beFalse()) + expect(3.isEven()).to(beFalse()) + + expect((-2).isEven()).to(beTrue()) + expect(4.isEven()).to(beTrue()) + + } + + /** + * Int.odd + */ + it("odd") { + + expect((-1).isOdd()).to(beTrue()) + expect(3.isOdd()).to(beTrue()) + + expect((-2).isOdd()).to(beFalse()) + expect(4.isOdd()).to(beFalse()) + + } + + /** + * Int.random + */ + it("random") { + + var indexes = [Int]() + 10.times { indexes.append(Int.random(min: 5, max: 25)) } + + expect(indexes).to(allPass { $0 >= 5 && $0 <= 25 }) + + } + + /** + * Int.upTo + */ + it("upTo") { + + var result = [Int]() + 5.upTo(10, function: result.append) + + expect(result) == [Int](5...10) + + } + + /** + * Int.downTo + */ + it("downTo") { + + var result = [Int]() + 5.downTo(0, function: result.append) + + expect(result) == [5, 4, 3, 2, 1, 0] + + } + + /** + * Int.clamp + */ + it("clamp") { + + expect(5.clamp(0...4)) == 4 + expect(3.clamp(0...4)) == 3 + expect(1.clamp(2...4)) == 2 + + } + + /** + * Int.isIn + */ + it("isIn") { + + expect(2.isIn(0..<3)).to(beTrue()) + expect(2.isIn(0..<3, strict: true)).to(beFalse()) + + expect(0.isIn(0..<3)).to(beTrue()) + expect(0.isIn(0..<3, strict: true)).to(beFalse()) + + expect(2.isIn(0...2)).to(beTrue()) + expect(2.isIn(0...2, strict: true)).to(beFalse()) + + } + + /** + * Int.explode + */ + it("explode") { + + expect(0.digits()) == [0] + + expect(1234.digits()) == [1, 2, 3, 4] + + } + + /** + * Int.gcd + */ + it("gcd") { + + expect(3.gcd(6)) == 3 + + expect(6.gcd(3)) == 3 + + expect(6124.gcd(342)) == 2 + + expect(342.gcd(6124)) == 2 + + } + + /** + * Int.lcm + */ + it("lcm") { + + expect(3.lcm(4)) == 12 + + expect(4.lcm(3)) == 12 + + } + + /** + * Int.abs + */ + it("abs") { + + expect((-1).abs()) == 1 + expect((-10).abs()) == 10 + + expect(1.abs()) == 1 + + expect(0.abs()) == 0 + + } + + describe("time") { + + it("years") { + + expect(0.years) == 0 + expect(1.year) == 31536000 + expect(111.years) == 31536000 * 111 + + expect(-1.year) == -31536000 + expect(-111.years) == -31536000 * 111 + + expect(0.year) == 0.years + expect(1.year) == 1.years + expect(1010.year) == 1010.years + + } + + it("days") { + + expect(0.days) == 0 + expect(1.day) == 86400 + expect(111.days) == 86400 * 111 + + expect(-1.day) == -86400 + expect(-111.days) == -86400 * 111 + + expect(0.day) == 0.days + expect(1.day) == 1.days + expect(1010.day) == 1010.days + + } + + it("hours") { + + expect(0.hours) == 0 + expect(1.hour) == 3600 + expect(111.hours) == 3600 * 111 + + expect(-1.hour) == -3600 + expect(-111.hours) == -3600 * 111 + + expect(0.hour) == 0.hours + expect(1.hour) == 1.hours + expect(1010.hour) == 1010.hours + + } + + it("minutes") { + + expect(0.minutes) == 0 + expect(1.minute) == 60 + expect(111.minutes) == 60 * 111 + + expect(-1.minute) == -60 + expect(-111.minutes) == -60 * 111 + + expect(0.minute) == 0.minutes + expect(1.minute) == 1.minutes + expect(1010.minute) == 1010.minutes + + } + + it("seconds") { + + expect(0.seconds) == 0 + expect(1.second) == 1 + expect(111.seconds) == 111 + + expect(-1.second) == -1 + expect(-111.seconds) == -111 + + expect(0.second) == 0.seconds + expect(1.second) == 1.seconds + expect(1010.second) == 1010.seconds + + } + + } + + } + +} diff --git a/ExSwiftTests/NSArrayExtensionsTests.swift b/ExSwiftTests/NSArrayExtensionsTests.swift new file mode 100644 index 0000000..6abbdec --- /dev/null +++ b/ExSwiftTests/NSArrayExtensionsTests.swift @@ -0,0 +1,41 @@ +// +// NSArrayExtensionsTests.swift +// ExSwift +// +// Created by pNre on 10/06/14. +// Copyright (c) 2014 pNre. All rights reserved. +// + +import Quick +import Nimble + +class NSArrayExtensionsSpec: QuickSpec { + + override func spec() { + + it("cast") { + + let array: NSArray = ["A", 10, "B", "C", false] + + expect(array.cast() as [NSNumber]) == [10, 0] + expect(array.cast() as [NSString]) == ["A", "B", "C"] + + expect(array.cast() as [Int]) == [10, 0] + + } + + it("flatten") { + + let array = [5, [6, ["A", 7]], 8] + + expect(array.flatten() as [NSNumber]) == [5, 6, 7, 8] + expect(array.flatten() as [Int]) == [5, 6, 7, 8] + expect(array.flatten() as [String]) == ["A"] + + expect(array.flattenAny() as? [NSObject]) == [5, 6, "A", 7, 8] + + } + + } + +} diff --git a/ExSwiftTests/NSDateExtensionsTests.swift b/ExSwiftTests/NSDateExtensionsTests.swift new file mode 100644 index 0000000..0a919ce --- /dev/null +++ b/ExSwiftTests/NSDateExtensionsTests.swift @@ -0,0 +1,258 @@ +// +// NSDateExtensionsTests.swift +// ExSwift +// +// Created by Piergiuseppe Longo on 23/11/14. +// Copyright (c) 2014 pNre. All rights reserved. +// + +import Quick +import Nimble + +class NSDateExtensionsSpec: QuickSpec { + + let dateFormatter = NSDateFormatter() + + var startDate: NSDate? + + override func spec() { + + beforeSuite { + + self.dateFormatter.dateFormat = "dd/MM/yyyy HH:mm:ss" + + } + + beforeEach { + + self.startDate = self.dateFormatter.dateFromString("30/11/1988 00:00:00") + + } + + describe("manipulation") { + + it("addSeconds") { + + var expectedDate = self.dateFormatter.dateFromString("30/11/1988 00:00:42") + + expect(self.startDate?.addSeconds(42)) == expectedDate + expect(self.startDate?.add(seconds: 42)) == expectedDate + + expectedDate = self.dateFormatter.dateFromString("29/11/1988 23:59:18") + + expect(self.startDate?.addSeconds(-42)) == expectedDate + expect(self.startDate?.add(seconds: -42)) == expectedDate + + } + + it("addMinutes") { + + var expectedDate = self.dateFormatter.dateFromString("30/11/1988 00:42:00") + + expect(self.startDate?.addMinutes(42)) == expectedDate + expect(self.startDate?.add(minutes: 42)) == expectedDate + + expectedDate = self.dateFormatter.dateFromString("29/11/1988 23:18:00") + + expect(self.startDate?.addMinutes(-42)) == expectedDate + expect(self.startDate?.add(minutes: -42)) == expectedDate + + } + + it("addHours") { + + var expectedDate = self.dateFormatter.dateFromString("01/12/1988 18:00:00") + + expect(self.startDate?.addHours(42)) == expectedDate + expect(self.startDate?.add(hours: 42)) == expectedDate + + expectedDate = self.dateFormatter.dateFromString("28/11/1988 06:00:00") + + expect(self.startDate?.addHours(-42)) == expectedDate + expect(self.startDate?.add(hours: -42)) == expectedDate + + } + + it("addDays") { + + var expectedDate = self.dateFormatter.dateFromString("02/12/1988 00:00:00") + + expect(self.startDate?.addDays(2)) == expectedDate + expect(self.startDate?.add(days: 2)) == expectedDate + + expectedDate = self.dateFormatter.dateFromString("19/10/1988 00:00:00") + + expect(self.startDate?.addDays(-42)) == expectedDate + expect(self.startDate?.add(days: -42)) == expectedDate + + } + + it("addWeeks") { + + var expectedDate = self.dateFormatter.dateFromString("7/12/1988 00:00:00") + + expect(self.startDate?.addWeeks(1)) == expectedDate + expect(self.startDate?.add(weeks: 1)) == expectedDate + + expectedDate = self.dateFormatter.dateFromString("23/11/1988 00:00:00") + + expect(self.startDate?.addWeeks(-1)) == expectedDate + expect(self.startDate?.add(weeks: -1)) == expectedDate + + } + + it("addMonths") { + + var expectedDate = self.dateFormatter.dateFromString("30/12/1988 00:00:00") + + expect(self.startDate?.addMonths(1)) == expectedDate + expect(self.startDate?.add(months: 1)) == expectedDate + + expectedDate = self.dateFormatter.dateFromString("30/10/1988 00:00:00") + + expect(self.startDate?.addMonths(-1)) == expectedDate + expect(self.startDate?.add(months: -1)) == expectedDate + + } + + it("addYears") { + + var expectedDate = self.dateFormatter.dateFromString("30/11/1989 00:00:00") + + expect(self.startDate?.addYears(1)) == expectedDate + expect(self.startDate?.add(years: 1)) == expectedDate + + expectedDate = self.dateFormatter.dateFromString("30/11/1987 00:00:00") + + expect(self.startDate?.addYears(-1)) == expectedDate + expect(self.startDate?.add(years: -1)) == expectedDate + + } + + it("add") { + + var expectedDate = self.dateFormatter.dateFromString("10/01/1990 18:42:42") + + expect(self.startDate?.add(seconds: 42, minutes: 42, hours: 42, days: 2, weeks: 1 , months: 1, years: 1)) == expectedDate + + expectedDate = self.dateFormatter.dateFromString("20/10/1987 22:17:18") + + expect(self.startDate?.add(seconds: -42, minutes: -42, hours: -1, days: -2, weeks: -1 , months: -1, years: -1)) == expectedDate + + } + + } + + describe("comparison") { + + it("isAfter") { + + let date = NSDate() + + var futureDate = date.addSeconds(42) + var pastDate = date.addSeconds(-42) + + expect(futureDate.isAfter(date)).to(beTrue()) + expect(date.isAfter(date)).to(beFalse()) + expect(pastDate.isAfter(date)).to(beFalse()) + + } + + it("isBefore") { + + let date = NSDate() + + var futureDate = date.addSeconds(42) + var pastDate = date.addSeconds(-42) + + expect(futureDate.isBefore(date)).to(beFalse()) + expect(date.isBefore(date)).to(beFalse()) + expect(pastDate.isBefore(date)).to(beTrue()) + + } + + } + + it("components properties") { + + expect(self.startDate!.year) == 1988 + expect(self.startDate!.month) == 11 + expect(self.startDate!.days) == 30 + expect(self.startDate!.hours) == 0 + expect(self.startDate!.minutes) == 0 + expect(self.startDate!.seconds) == 0 + expect(self.startDate!.weekday) == 4 + expect(self.startDate!.weekMonth) == 5 + + } + + describe("comparable") { + + it("sorting") { + + let firstDate = self.startDate!.addSeconds(0) + let secondDate = self.startDate!.addSeconds(42) + let thirdDate = self.startDate!.addSeconds(-42) + let fourthDate = self.startDate!.addSeconds(-84) + let fifthDate = self.startDate!.addSeconds(84) + + var dates = [thirdDate, secondDate, firstDate, fourthDate, fifthDate] + + let expected = [fifthDate, secondDate, firstDate, thirdDate, fourthDate] + let expectedReverded = expected.reverse() + + for i in 0 ... 42 { + dates.shuffle() + + dates.sort( { $0 > $1 } ) + expect(dates) == expected + + dates.sort( { $0 < $1 } ) + expect(dates) == expectedReverded + } + + } + + it("comparable") { + + let date = self.startDate!.addSeconds(-42) + let anotherDate = self.startDate!.addSeconds(42) + let shouldBeTheSameDate = NSDate(timeInterval: 0, sinceDate: self.startDate!) + + expect(self.startDate) == shouldBeTheSameDate + + expect(self.startDate) > date + expect(self.startDate) >= date + + expect(self.startDate) <= anotherDate + expect(self.startDate) < anotherDate + + expect(date) != self.startDate + expect(anotherDate) != self.startDate + + } + + } + + it("arithmetic") { + + let date = NSDate() as NSDate + + expect(date.timeIntervalSinceDate(date - 1.hour)) == 1.hour + expect(date.timeIntervalSinceDate(date + 1.hour)) == -1.hour + + var otherDate = date + + otherDate -= 1.minute + expect(otherDate) !== date + expect(date.timeIntervalSinceDate(otherDate)) == 1.minute + + otherDate += 1.hour + expect(date.timeIntervalSinceDate(otherDate)) == 1.minute - 1.hour + + } + + } + +} + diff --git a/ExSwiftTests/RangeExtensionsTests.swift b/ExSwiftTests/RangeExtensionsTests.swift new file mode 100644 index 0000000..cf12d64 --- /dev/null +++ b/ExSwiftTests/RangeExtensionsTests.swift @@ -0,0 +1,52 @@ +// +// RangeExtensionsTests.swift +// ExSwift +// +// Created by pNre on 04/06/14. +// Copyright (c) 2014 pNre. All rights reserved. +// + +import Quick +import Nimble + +class RangeExtensionsSpec: QuickSpec { + + override func spec() { + + /** + * Range.times + */ + it("times") { + + var count: Int = 0 + (2..<4).times { count++ } + + expect(count) == 2 + + count = 0 + (2...4).times { count++ } + + expect(count) == 3 + + } + + /** + * Range.each + */ + it("each") { + + var items = [Int]() + (0..<2).each(items.append) + + expect(items) == [0, 1] + + (0..<0).each { (current: Int) in + fail() + } + + } + + } + +} + diff --git a/ExSwiftTests/SequenceExtensionsTests.swift b/ExSwiftTests/SequenceExtensionsTests.swift new file mode 100644 index 0000000..74829ae --- /dev/null +++ b/ExSwiftTests/SequenceExtensionsTests.swift @@ -0,0 +1,140 @@ +// +// SequenceExtensionsTests.swift +// ExSwift +// +// Created by Colin Eberhardt on 24/06/2014. +// Copyright (c) 2014 pNre. All rights reserved. +// + + +import Quick +import Nimble + +class SequenceExtensionsSpec: QuickSpec { + + var sequence = 1...5 + var emptySequence = 1..<1 + + override func spec() { + + it("first") { + + expect(SequenceOf(self.sequence).first) == 1 + + expect(SequenceOf(self.emptySequence).first).to(beNil()) + + } + + it("contains") { + + expect(SequenceOf(self.sequence).contains(1)).to(beTrue()) + expect(SequenceOf(self.sequence).contains(56)).to(beFalse()) + + } + + it("indexOf") { + + expect(SequenceOf(self.sequence).indexOf(2)) == 1 + expect(SequenceOf(self.sequence).indexOf(56)).to(beNil()) + + } + + it("skip") { + + expect(Array(SequenceOf(self.sequence).skip(0))) == Array(SequenceOf(self.sequence)) + + expect(Array(SequenceOf(self.sequence).skip(2))) == [3, 4, 5] + + expect(Array(SequenceOf(self.sequence).skip(8))) == [] + + } + + it("skipWhile") { + + expect(Array(SequenceOf(self.sequence).skipWhile { $0 < 3 })) == [3, 4, 5] + + expect(Array(SequenceOf(self.sequence).skipWhile { $0 < 20 })) == [] + + } + + it("take") { + + expect(Array(SequenceOf(self.sequence).take(0))) == [] + + expect(Array(SequenceOf(self.sequence).take(2))) == [1, 2] + + expect(Array(SequenceOf(self.sequence).take(20))) == Array(SequenceOf(self.sequence)) + + } + + it("takeWhile") { + + expect(Array(SequenceOf(self.sequence).takeWhile { $0 != 3 })) == [1, 2] + + expect(Array(SequenceOf(self.sequence).takeWhile { $0 == 7 })) == [] + + expect(Array(SequenceOf(self.sequence).takeWhile { $0 != 7 })) == [1, 2, 3, 4, 5] + + } + + describe("get") { + + it("index") { + + expect(SequenceOf(self.sequence).get(3)) == 3 + expect(SequenceOf(self.sequence).get(22)).to(beNil()) + + } + + it("range") { + + expect(Array(SequenceOf(self.sequence).get(1..<3))) == [2, 3] + + expect(Array(SequenceOf(self.sequence).get(0..<0))) == [] + + expect(Array(SequenceOf(self.sequence).get(10..<15))) == [] + + } + + } + + it("any") { + + expect(SequenceOf(self.sequence).any { $0 == 1 }).to(beTrue()) + + expect(SequenceOf(self.sequence).any { $0 == 77 }).to(beFalse()) + + } + + it("filter") { + + var evens = SequenceOf(self.sequence).filter { $0 % 2 == 0 } + expect(Array(evens)) == [2, 4] + + var odds = SequenceOf(self.sequence).filter { $0 % 2 == 1 } + expect(Array(odds)) == [1, 3, 5] + + var all = SequenceOf(self.sequence).filter { $0 < 10 } + expect(Array(all)) == [1, 2, 3, 4, 5] + + var none = SequenceOf(self.sequence).filter { $0 > 10 } + expect(Array(none)) == [] + + } + + it("reject") { + + var rejected = SequenceOf(self.sequence).reject { $0 == 3 } + expect(Array(rejected)) == [1, 2, 4, 5] + + rejected = SequenceOf(self.sequence).reject { $0 == 1 } + expect(Array(rejected)) == [2, 3, 4, 5] + + rejected = SequenceOf(self.sequence).reject { $0 == 10 } + expect(Array(rejected)) == [1, 2, 3, 4, 5] + + } + + } + +} diff --git a/ExSwiftTests/StringExtensionsTests.swift b/ExSwiftTests/StringExtensionsTests.swift new file mode 100644 index 0000000..dc14fce --- /dev/null +++ b/ExSwiftTests/StringExtensionsTests.swift @@ -0,0 +1,325 @@ +// +// StringExtensionsTests.swift +// ExSwift +// +// Created by ExSwift on 04/06/14. +// Copyright (c) 2014 pNre. All rights reserved. +// + +import Quick +import Nimble + +class StringExtensionsSpec: QuickSpec { + + override func spec() { + + /** + * String.length + */ + it("length") { + + expect("".length) == 0 + expect("A".length) == 1 + expect("😱".length) == 1 + expect("∞".length) == 1 + expect("∞aA".length) == 3 + + } + + /** + * String[x] + */ + it("subscript") { + + let string = "βˆ†TestπŸ˜—" + + expect(string[0]) == "βˆ†" + expect(string[1]) == "T" + + expect(string[string.length - 1]) == "πŸ˜—" + expect(string[1..<6]) == "TestπŸ˜—" + + if let s = "hello"[0] { + expect(s) == "h" + } else { + fail("string[0]") + } + + expect("ABCD"[0, 2]) == ["A", "C"] + + } + + /** + * String.at + */ + it("at") { + + expect("ABCD".at(0)) == ["A"] + expect("ABCD".at(0)) == ["ABCD"[0]!] + + expect("ABCD".at(0, 2)) == ["A", "C"] + expect("ABCD".at(0, 2)) == "ABCD"[0, 2] + + } + + /** + * String.explode + */ + it("explode") { + + expect("A B C".explode(" ")) == ["A", "B", "C"] + + expect("A B C".explode(">")) == ["A B C"] + expect("A>B C".explode(">")) == ["A", "B C"] + + } + + /** + * String.capitalized + */ + it("capitalized") { + + expect("".capitalized) == "" + expect("abcdef".capitalized) == "Abcdef" + expect("Abcdef".capitalized) == "Abcdef" + + } + + /** + * String.insert + */ + it("insert") { + + expect("abcdef".insert(0, "X")) == "Xabcdef" + + expect("abcdef".insert(10, "X")) == "abcdefX" + expect("abcdef".insert(3, "X")) == "abcXdef" + + } + + /** + * String.repeat + */ + it("repeat operator") { + + expect("A" * 3) == "AAA" + expect("A" * 0) == "" + + } + + /** + * String pattern matching + */ + describe("matching") { + + it("=~") { + + let string = "ABcd" + + expect(string =~ "^A").to(beTrue()) + + expect(string =~ (pattern: "D$", ignoreCase: true)).to(beTrue()) + expect(string =~ "D$").to(beFalse()) + + // String[] all + let strings = [string, string, string] + + expect(strings =~ "^A").to(beTrue()) + + expect(strings =~ (pattern: "D$", ignoreCase: true)).to(beTrue()) + expect(strings =~ "D$").to(beFalse()) + + } + + it("|~") { + + // String[] any + let strings = ["ABcd", "ABcd", "ABcd"] + + XCTAssertTrue(strings |~ "^A") + + XCTAssertTrue(strings |~ (pattern: "D$", ignoreCase: true)) + XCTAssertFalse(strings |~ "D$") + + } + + it("matches") { + + let string = "AB[31]" + + let matches = string.matches("\\d+")! + let range = matches[0].rangeAtIndex(0) + + let substringRange = range.location..<(range.location + range.length) + + expect(string[substringRange]) == "31" + expect(string.matches("N")!.isEmpty).to(beTrue()) + + } + + } + + /** + * String trimming methods + */ + describe("trimming") { + + it("trimmed") { + + expect("t e".trimmed()) == "t e" + expect(" AB".trimmed()) == "AB" + expect("\n ABC ".trimmed()) == "ABC" + expect("".trimmed()) == "" + expect(" \t\n\r".trimmed()) == "" + + } + + describe("trimmedLeft") { + + it("default character set") { + + expect("ab ".trimmedLeft()) == "ab " + expect("ab".trimmedLeft()) == "ab" + expect(" AB".trimmedLeft()) == "AB" + expect("\n ABC ".trimmedLeft()) == "ABC " + expect("".trimmedLeft()) == "" + expect(" \t\n\r".trimmedLeft()) == "" + + } + + it("with character set") { + + expect("ab ".trimmedLeft(characterSet: NSCharacterSet.alphanumericCharacterSet())) == " " + expect(" ab".trimmedLeft(characterSet: NSCharacterSet.alphanumericCharacterSet())) == " ab" + expect("ab".trimmedLeft(characterSet: NSCharacterSet.alphanumericCharacterSet())) == "" + + } + + } + + describe("trimmedRight") { + + it("default character set") { + + expect("t e".trimmedRight()) == "t e" + expect(" AB".trimmedRight()) == " AB" + expect("AB ".trimmedRight()) == "AB" + expect("\n ABC ".trimmedRight()) == "\n ABC" + expect("".trimmedRight()) == "" + expect(" \t\n\r".trimmedRight()) == "" + + } + + it("with character set") { + + expect("ab ".trimmedRight(characterSet: NSCharacterSet.alphanumericCharacterSet())) == "ab " + expect(" ab".trimmedRight(characterSet: NSCharacterSet.alphanumericCharacterSet())) == " " + expect("ab".trimmedRight(characterSet: NSCharacterSet.alphanumericCharacterSet())) == "" + + } + + } + + describe("type conversion") { + + it("toDouble") { + + expect(" 7.2 ".toDouble()).to(beCloseTo(7.2, within: 0.0001)) + expect("-70.211111 ".toDouble()).to(beCloseTo(-70.211111, within: 0.0001)) + expect("42".toDouble()).to(beCloseTo(42, within: 0.0001)) + + expect("a772.2".toDouble()).to(beNil()) + + } + + it("toFloat") { + + expect(" 7.2 ".toFloat()).to(beCloseTo(7.2, within: 0.0001)) + expect("-70.211111 ".toFloat()).to(beCloseTo(-70.211111, within: 0.0001)) + expect("42".toFloat()).to(beCloseTo(42, within: 0.0001)) + + expect("a772.2".toFloat()).to(beNil()) + + } + + it("toUInt") { + + expect(" 7 ".toUInt()) == 7 + + expect("a772.2".toUInt()).to(beNil()) + expect("-772".toUInt()).to(beNil()) + expect("7.5".toUInt()).to(beNil()) + + } + + it("toBool") { + + expect(" TrUe ".toBool()).to(beTrue()) + expect(" yEs ".toBool()).to(beTrue()) + + expect(" FALSE ".toBool()).to(beFalse()) + expect(" nO ".toBool()).to(beFalse()) + + expect("".toBool()).to(beNil()) + expect("jeff".toBool()).to(beNil()) + expect("0".toBool()).to(beNil()) + + } + + it("toDate") { + + var d : NSDate = " 2015-08-19 \t ".toDate()! + + var c = NSDateComponents() + c.year = 2015 + c.month = 8 + c.day = 19 + + var gregorian = NSCalendar(identifier: NSGregorianCalendar)! + expect(gregorian.dateFromComponents(c)) == d + + expect("a772.2".toDate()).to(beNil()) + expect("Tuesday".toDate()).to(beNil()) + expect("1973-08-19 03:04:55".toDate()).to(beNil()) + + } + + it("toDateTime") { + + var d : NSDate = " 2015-08-19 03:04:34\t ".toDateTime()! + + var c = NSDateComponents() + c.year = 2015 + c.month = 8 + c.day = 19 + c.hour = 3 + c.minute = 4 + c.second = 34 + + var gregorian = NSCalendar(identifier: NSGregorianCalendar)! + expect(gregorian.dateFromComponents(c)) == d + + expect("a772.2".toDateTime()).to(beNil()) + expect("Tuesday".toDateTime()).to(beNil()) + expect("1973-08-19".toDateTime()).to(beNil()) + + } + + } + + /** + * String.random + */ + it("random") { + + expect(String.random().length).to(beLessThanOrEqualTo(16)) + expect(String.random(length: 12).length) == 12 + + } + + } + + } + +} + diff --git a/Podfile b/Podfile new file mode 100644 index 0000000..738c5c5 --- /dev/null +++ b/Podfile @@ -0,0 +1,9 @@ +inhibit_all_warnings! +use_frameworks! + +target :ExSwiftTests do + platform :osx, '10.10' + + pod 'Quick' + pod 'Nimble' +end diff --git a/Podfile.lock b/Podfile.lock new file mode 100644 index 0000000..fc33353 --- /dev/null +++ b/Podfile.lock @@ -0,0 +1,13 @@ +PODS: + - Nimble (0.4.2) + - Quick (0.3.1) + +DEPENDENCIES: + - Nimble + - Quick + +SPEC CHECKSUMS: + Nimble: 49b7a7da8919f42823d37c6d68cc6d15a7009f32 + Quick: 824572d3d198d51e52cf4aa722cebf7e59952a35 + +COCOAPODS: 0.36.3