diff --git a/README.md b/README.md index b5b88ed..db1b6b0 100644 --- a/README.md +++ b/README.md @@ -8,40 +8,47 @@ let myHeight = 34.5 let myWidth = 100.23 let sizeOfWindow = CGSize(width:myWidth, height:myHeight) +let myDouble:Double = sizeOfWindow.height // .height is a CGFloat +let isLargerThan = 213.3 > sizeOfWindow.width // 213.3 is a Double + + +//You can now compare or do mathematical operations on the following: + var doubleValue:Double = 5.0 + var cgFloatValue:CGFloat = 5.0 + var intValue:Int = 5 + var int16Value:Int16 = 5 + var int32Value:Int32 = 5 + var int64Value:Int64 = 5 + var uInt16Value:UInt16 = 5 + var uInt32Value:UInt32 = 5 + var uInt64Value:UInt64 = 5 ```` + ### Overview -Adds math functions as properties and takes care of operators for interacting between different types of scalars. +Takes care of operators for interacting between different types of scalars. This library makes it easier to compare to ```Int```, ```Float``` and ```CGFloat``` regardless of architecture. +This also makes implicit casts to Double or CGFloat for arguments or variables that takes either types. + + ``var myDouble = 2.0`` will give you a ```Double``` and you'd want to use that with other types. -Since ```CGFloat``` is not a ```Double``` on 32bit, it becomes hard to use CGGeomtry and frameworks like CoreGraphics or SpriteKit. This library makes it a little easier and hopefully Apple takes care of it soon. +Since ```CGFloat``` is not a ```Double``` on 32bit, it becomes hard to use CGGeometry and frameworks like CoreGraphics or SpriteKit. This library makes it a little easier and hopefully Apple takes care of it soon. Works on both Mac OS and iOS. + + + ### Math Functions -```swift -protocol ScalarFunctions { - var acos:Double {get} - var asin:Double {get} - var atan:Double {get} - func atan2(x:Double) -> Double - var cos:Double {get} - var sin:Double {get} - var tan:Double {get} - var exp:Double {get} - var exp2:Double {get} - var log:Double {get} - var log10:Double {get} - var log2:Double {get} - func pow(exponent:Double) -> Double - var sqrt:Double {get} -} +Many people disagreed with the global math functions being used as properties. I was on the fence on that one because I didn't want to write over them for 32 bit. However now that implicit casts are in place. This works on 32bit. +```swift +let yay = abs(2.0) ``` diff --git a/ScalarArithmetic.podspec b/ScalarArithmetic.podspec index b285dd3..f397fa7 100644 --- a/ScalarArithmetic.podspec +++ b/ScalarArithmetic.podspec @@ -3,7 +3,7 @@ Pod::Spec.new do |s| url = "https://github.com/seivan/#{name}" git_url = "#{url}.git" s.name = name - version = "1.0.0" + version = "1.1.0" source_files = "#{name}/**/*.{swift}" s.version = version diff --git a/ScalarArithmetic/ScalarArithmetic.swift b/ScalarArithmetic/ScalarArithmetic.swift index 72034bc..f499e35 100644 --- a/ScalarArithmetic/ScalarArithmetic.swift +++ b/ScalarArithmetic/ScalarArithmetic.swift @@ -1,214 +1,139 @@ -import Darwin -import CoreGraphics -import Foundation - -protocol ScalarFunctions { - var acos:Double {get} - var asin:Double {get} - var atan:Double {get} - func atan2(x:Double) -> Double - var cos:Double {get} - var sin:Double {get} - var tan:Double {get} - var exp:Double {get} - var exp2:Double {get} - var log:Double {get} - var log10:Double {get} - var log2:Double {get} - func pow(exponent:Double) -> Double - var sqrt:Double {get} -} - - -extension Double : ScalarFunctions { - var abs:Double { return Double.abs(self) } - var acos:Double { return Darwin.acos(self) } - var asin:Double { return Darwin.asin(self) } - var atan:Double { return Darwin.atan(self) } - func atan2(x:Double) -> Double { return Darwin.atan2(self,x) } - var cos:Double { return Darwin.cos(self) } - var sin:Double { return Darwin.sin(self) } - var tan:Double { return Darwin.tan(self) } - var exp:Double { return Darwin.exp(self) } - var exp2:Double { return Darwin.exp2(self) } - var log:Double { return Darwin.log(self) } - var log10:Double{ return Darwin.log10(self) } - var log2:Double { return Darwin.log2(self) } - func pow(exponent:Double)-> Double { return Darwin.pow(self, exponent) } - var sqrt:Double { return Darwin.sqrt(self) } -} - -protocol ScalarArithmetic { - var toDouble:Double { get } - init(_ value:Double) -} - -extension Int : ScalarArithmetic { - var toDouble:Double { return Double(self) } -} - #if !(arch(x86_64) || arch(arm64)) -extension CGFloat : ScalarArithmetic, ScalarFunctions { - var toDouble:Double { return Double(self) } - var abs:Double { return Double(self).abs } - var acos:Double { return Double(self).acos } - var asin:Double { return Double(self).asin } - var atan:Double { return Double(self).atan } - func atan2(x:Double) -> Double { return Double(self).atan2(x) } - var cos:Double { return Double(self).cos } - var sin:Double { return Double(self).sin } - var tan:Double { return Double(self).tan } - var exp:Double { return Double(self).exp } - var exp2:Double { return Double(self).exp2 } - var log:Double { return Double(self).log } - var log10:Double { return Double(self).log10} - var log2:Double { return Double(self).log2 } - func pow(exponent:Double)-> Double { return Double(self).pow(exponent) } - var sqrt:Double { return Double(self).sqrt } -} - -#endif + import CoreGraphics + extension Int { + @conversion func __conversion() -> CGFloat { + return CGFloat(self) + } + } -//Equality T<===>T -//@infix func == (lhs:T,rhs:U) -> Bool { -// return (lhs.toDouble == rhs.toDouble) -//} -//@infix func != (lhs:T,rhs:U) -> Bool { -// return (lhs == rhs) == false -//} -@infix func <= (lhs:T,rhs:U) -> Bool { - return (lhs.toDouble <= rhs.toDouble) -} -@infix func < (lhs:T,rhs:U) -> Bool { - return (lhs.toDouble < rhs.toDouble) -} -@infix func >= (lhs:T,rhs:U) -> Bool { - return (lhs < rhs) == false -} -@infix func > (lhs:T,rhs:U) -> Bool { - return (lhs <= rhs) == false -} + extension CGFloat { + @conversion func __conversion() -> Double { + return Double(self) + } + } -//Equality Double<==>T -//@infix func == (lhs:Double, rhs:T) -> Bool { -// return (lhs == rhs.toDouble) -//} -//@infix func != (lhs:Double, rhs:T) -> Bool { -// return (lhs == rhs) == false -//} -@infix func <= (lhs:Double, rhs:T) -> Bool { - return (lhs <= rhs.toDouble) -} -@infix func < (lhs:Double, rhs:T) -> Bool { - return (lhs < rhs.toDouble) -} -@infix func >= (lhs:Double, rhs:T) -> Bool { - return (lhs < rhs) == false -} -@infix func > (lhs:Double, rhs:T) -> Bool { - return (lhs <= rhs) == false -} + extension Int16 { + @conversion func __conversion() -> CGFloat { + return CGFloat(self) + } + + } + + extension Int32 { + + @conversion func __conversion() -> CGFloat { + return CGFloat(self) + } + + } + + extension Int64 { + + @conversion func __conversion() -> CGFloat { + return CGFloat(self) + } + + } + + + extension UInt16 { + @conversion func __conversion() -> CGFloat { + return CGFloat(self) + } + + } + + extension UInt32 { + + @conversion func __conversion() -> CGFloat { + return CGFloat(self) + } + + } + + extension UInt64 { + + @conversion func __conversion() -> CGFloat { + return CGFloat(self) + } + + } -//Equality T<==>Double -//@infix func == (lhs:T,rhs:Double) -> Bool { -// return (lhs.toDouble == rhs) -//} -//@infix func != (lhs:T,rhs:Double) -> Bool { -// return (lhs == rhs) == false -//} -@infix func <= (lhs:T,rhs:Double) -> Bool { - return (lhs.toDouble <= rhs) -} -@infix func < (lhs:T,rhs:Double) -> Bool { - return (lhs.toDouble < rhs) -} -@infix func >= (lhs:T,rhs:Double) -> Bool { - return (lhs < rhs) == false -} -@infix func > (lhs:T,rhs:Double) -> Bool { - return (lhs <= rhs) == false -} +#endif -//SUBTRACTION -@infix func - (lhs: T, rhs:U) -> Double { - return lhs.toDouble - rhs.toDouble -} -@infix func - (lhs:Double, rhs:T) -> Double { - return lhs - rhs.toDouble -} -@infix func - (lhs:T, rhs:Double) -> Double { - return lhs.toDouble - rhs -} -@assignment @infix func -= (inout lhs:Double, rhs:T) { - lhs = lhs - rhs.toDouble +extension Int { + @conversion func __conversion() -> Double { + return Double(self) + } } -//ADDITION -@infix func + (lhs: T, rhs:U) -> Double { - return lhs.toDouble + rhs.toDouble -} -@infix func + (lhs:Double, rhs:T) -> Double { - return lhs + rhs.toDouble -} -@infix func + (lhs:T, rhs:Double) -> Double { - return lhs.toDouble + rhs -} -@assignment @infix func += (inout lhs:Double, rhs:T) { - lhs = lhs + rhs.toDouble +extension Int16 { + @conversion func __conversion() -> Int { + return Int(self) + } + @conversion func __conversion() -> Double { + return Double(self) + } + } -//MULTIPLICATION -@infix func * (lhs: T, rhs:U) -> Double { - return lhs.toDouble * rhs.toDouble -} -@infix func * (lhs:Double, rhs:T) -> Double { - return lhs * rhs.toDouble -} -@infix func * (lhs:T, rhs:Double) -> Double { - return lhs.toDouble * rhs -} -@assignment @infix func *= (inout lhs:Double, rhs:T) { - lhs = lhs * rhs.toDouble +extension Int32 { + @conversion func __conversion() -> Int { + return Int(self) + } + + @conversion func __conversion() -> Double { + return Double(self) + } + } -//DIVISION -@infix func / (lhs: T, rhs:U) -> Double { - return lhs.toDouble / rhs.toDouble -} -@infix func / (lhs: Double, rhs:T) -> Double { - return lhs / rhs.toDouble -} -@infix func / (lhs: T, rhs:Double) -> Double { - return lhs.toDouble / rhs -} -@assignment @infix func /= (inout lhs:Double, rhs:T) { - lhs = lhs / rhs.toDouble +extension Int64 { + @conversion func __conversion() -> Int { + return Int(self) + } + + @conversion func __conversion() -> Double { + return Double(self) + } + } -#if !(arch(x86_64) || arch(arm64)) -extension CGPoint { - init(x:Double, y:Double) { - self.init(x:CGFloat(x), y:CGFloat(y)) +extension UInt16 { + @conversion func __conversion() -> Int { + return Int(self) } + @conversion func __conversion() -> Double { + return Double(self) + } + } - -extension CGSize { - init(width:Double, height:Double) { - self.init(width:CGFloat(width), height:CGFloat(height)) +extension UInt32 { + @conversion func __conversion() -> Int { + return Int(self) } + + @conversion func __conversion() -> Double { + return Double(self) + } + } -extension CGVector { - init(_ dx:Double, _ dy:Double) { - self.dx = CGFloat(dx) - self.dy = CGFloat(dy) +extension UInt64 { + @conversion func __conversion() -> Int { + return Int(self) } + + @conversion func __conversion() -> Double { + return Double(self) + } + } -#endif + diff --git a/TestsAndSample/TestsAndSample.xcodeproj/project.pbxproj b/TestsAndSample/TestsAndSample.xcodeproj/project.pbxproj index 08ccb86..608e1c1 100644 --- a/TestsAndSample/TestsAndSample.xcodeproj/project.pbxproj +++ b/TestsAndSample/TestsAndSample.xcodeproj/project.pbxproj @@ -15,8 +15,6 @@ 226C9AF819622393002E395C /* TestsIntArithmeticTesting.swift in Sources */ = {isa = PBXBuildFile; fileRef = 226C9AF719622393002E395C /* TestsIntArithmeticTesting.swift */; }; 22AFC47F195F9D02003572F3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22AFC47E195F9D02003572F3 /* AppDelegate.swift */; }; 22AFC481195F9D02003572F3 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 22AFC480195F9D02003572F3 /* Images.xcassets */; }; - 22AFC48D195F9D02003572F3 /* TestsDoubleFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22AFC48C195F9D02003572F3 /* TestsDoubleFunctions.swift */; }; - 22AFC49D195FAF2A003572F3 /* TestsCGFloatFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22AFC49C195FAF2A003572F3 /* TestsCGFloatFunctions.swift */; }; 22AFC4A019603997003572F3 /* ScalarArithmetic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22AFC49F19603997003572F3 /* ScalarArithmetic.swift */; }; 22AFC4A119603997003572F3 /* ScalarArithmetic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22AFC49F19603997003572F3 /* ScalarArithmetic.swift */; }; 22AFC4A519603BBE003572F3 /* SuperTestsScalarArithmetic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22AFC4A419603BBE003572F3 /* SuperTestsScalarArithmetic.swift */; }; @@ -46,8 +44,6 @@ 22AFC480195F9D02003572F3 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 22AFC486195F9D02003572F3 /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 22AFC48B195F9D02003572F3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 22AFC48C195F9D02003572F3 /* TestsDoubleFunctions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestsDoubleFunctions.swift; sourceTree = ""; }; - 22AFC49C195FAF2A003572F3 /* TestsCGFloatFunctions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestsCGFloatFunctions.swift; sourceTree = ""; }; 22AFC49F19603997003572F3 /* ScalarArithmetic.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScalarArithmetic.swift; sourceTree = ""; }; 22AFC4A419603BBE003572F3 /* SuperTestsScalarArithmetic.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SuperTestsScalarArithmetic.swift; sourceTree = ""; }; 22AFC4A61960769A003572F3 /* SuperTestsScalarComparable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SuperTestsScalarComparable.swift; sourceTree = ""; }; @@ -116,8 +112,6 @@ 226C9AF319622257002E395C /* TestsDoubleArithmeticTesting.swift */, 226C9AF519622386002E395C /* TestsCGFloatArithmeticTesting.swift */, 226C9AF719622393002E395C /* TestsIntArithmeticTesting.swift */, - 22AFC48C195F9D02003572F3 /* TestsDoubleFunctions.swift */, - 22AFC49C195FAF2A003572F3 /* TestsCGFloatFunctions.swift */, 226C9AED19621EA9002E395C /* TestsDoubleComparable.swift */, 226C9AEF19621F3F002E395C /* TestsCGFloatComparable.swift */, 226C9AF119621F4B002E395C /* TestsIntComparable.swift */, @@ -250,7 +244,6 @@ buildActionMask = 2147483647; files = ( 226C9AF019621F3F002E395C /* TestsCGFloatComparable.swift in Sources */, - 22AFC49D195FAF2A003572F3 /* TestsCGFloatFunctions.swift in Sources */, 226C9AF419622257002E395C /* TestsDoubleArithmeticTesting.swift in Sources */, 22AFC4A519603BBE003572F3 /* SuperTestsScalarArithmetic.swift in Sources */, 226C9AEE19621EA9002E395C /* TestsDoubleComparable.swift in Sources */, @@ -259,7 +252,6 @@ 226C9AF619622386002E395C /* TestsCGFloatArithmeticTesting.swift in Sources */, 226C9AF819622393002E395C /* TestsIntArithmeticTesting.swift in Sources */, 226C9AF219621F4B002E395C /* TestsIntComparable.swift in Sources */, - 22AFC48D195F9D02003572F3 /* TestsDoubleFunctions.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/TestsAndSample/TestsAndSample.xcodeproj/project.xcworkspace/xcshareddata/TestsAndSample.xccheckout b/TestsAndSample/TestsAndSample.xcodeproj/project.xcworkspace/xcshareddata/TestsAndSample.xccheckout new file mode 100644 index 0000000..669ac02 --- /dev/null +++ b/TestsAndSample/TestsAndSample.xcodeproj/project.xcworkspace/xcshareddata/TestsAndSample.xccheckout @@ -0,0 +1,41 @@ + + + + + IDESourceControlProjectFavoriteDictionaryKey + + IDESourceControlProjectIdentifier + 3278BC64-4F30-43BB-B073-6A6A4038E096 + IDESourceControlProjectName + TestsAndSample + IDESourceControlProjectOriginsDictionary + + 52F35589-E053-4D9B-871C-7E7CAC859E0B + ssh://github.com/seivan/ScalarArithmetic.git + + IDESourceControlProjectPath + TestsAndSample/TestsAndSample.xcodeproj/project.xcworkspace + IDESourceControlProjectRelativeInstallPathDictionary + + 52F35589-E053-4D9B-871C-7E7CAC859E0B + ../../.. + + IDESourceControlProjectURL + ssh://github.com/seivan/ScalarArithmetic.git + IDESourceControlProjectVersion + 110 + IDESourceControlProjectWCCIdentifier + 52F35589-E053-4D9B-871C-7E7CAC859E0B + IDESourceControlProjectWCConfigurations + + + IDESourceControlRepositoryExtensionIdentifierKey + public.vcs.git + IDESourceControlWCCIdentifierKey + 52F35589-E053-4D9B-871C-7E7CAC859E0B + IDESourceControlWCCName + ScalarArithmetic + + + + diff --git a/TestsAndSample/TestsAndSample/AppDelegate.swift b/TestsAndSample/TestsAndSample/AppDelegate.swift index e44ac56..66d92ce 100644 --- a/TestsAndSample/TestsAndSample/AppDelegate.swift +++ b/TestsAndSample/TestsAndSample/AppDelegate.swift @@ -13,12 +13,50 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? + + + + func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { self.window = UIWindow(frame: UIScreen.mainScreen().bounds) // Override point for customization after application launch. self.window!.backgroundColor = UIColor.whiteColor() self.window!.makeKeyAndVisible() + + + var doubleValue:Double = 5.0 + var cgFloatValue:CGFloat = 5.0 + var intValue:Int = 5 + var int16Value:Int16 = 5 + var int32Value:Int32 = 5 + var int64Value:Int64 = 5 + var uInt16Value:UInt16 = 5 + var uInt32Value:UInt32 = 5 + var uInt64Value:UInt64 = 5 + + doubleValue = doubleValue + int16Value + doubleValue = doubleValue + int32Value + doubleValue = doubleValue + int64Value + + doubleValue = doubleValue + uInt16Value + doubleValue = doubleValue + uInt32Value + doubleValue = doubleValue + uInt64Value + + cgFloatValue = cgFloatValue + int16Value + cgFloatValue = cgFloatValue + int32Value + cgFloatValue = cgFloatValue + int64Value + + cgFloatValue = cgFloatValue + uInt16Value + cgFloatValue = cgFloatValue + uInt32Value + cgFloatValue = cgFloatValue + uInt64Value + + intValue = intValue + int64Value + intValue = intValue + uInt64Value + intValue = uInt64Value + int64Value + + intValue > int64Value + return true } diff --git a/TestsAndSample/TestsAndSampleTests/SuperTestsScalarArithmetic.swift b/TestsAndSample/TestsAndSampleTests/SuperTestsScalarArithmetic.swift index 2951a9f..6cbefa9 100644 --- a/TestsAndSample/TestsAndSampleTests/SuperTestsScalarArithmetic.swift +++ b/TestsAndSample/TestsAndSampleTests/SuperTestsScalarArithmetic.swift @@ -23,6 +23,13 @@ class SuperTestsScalarArithmetic: XCTestCase { let doubleValue:Double = 5.0 let cgFloatValue:CGFloat = 5.0 let intValue:Int = 5 + let int16Value:Int16 = 5 + let int32Value:Int32 = 5 + let int64Value:Int64 = 5 + let uInt16Value:UInt16 = 5 + let uInt32Value:UInt32 = 5 + let uInt64Value:UInt64 = 5 + var expectedValue:Double? var assignmentValue:Double = 0.0 diff --git a/TestsAndSample/TestsAndSampleTests/SuperTestsScalarComparable.swift b/TestsAndSample/TestsAndSampleTests/SuperTestsScalarComparable.swift index 79ced22..65d73d5 100644 --- a/TestsAndSample/TestsAndSampleTests/SuperTestsScalarComparable.swift +++ b/TestsAndSample/TestsAndSampleTests/SuperTestsScalarComparable.swift @@ -20,6 +20,13 @@ protocol ScalarComparableTesting { class SuperTestsScalarComparable: XCTestCase { var cgFloatValue = CGFloat(2.0) - var doubleValue = Double(2.0) + var doubleValue = Double(2.0) var intValue = 2 + let int16Value:Int16 = 2 + let int32Value:Int32 = 2 + let int64Value:Int64 = 2 + let uInt16Value:UInt16 = 2 + let uInt32Value:UInt32 = 2 + let uInt64Value:UInt64 = 2 + } diff --git a/TestsAndSample/TestsAndSampleTests/TestsCGFloatArithmeticTesting.swift b/TestsAndSample/TestsAndSampleTests/TestsCGFloatArithmeticTesting.swift index 70c3b8b..f83e602 100644 --- a/TestsAndSample/TestsAndSampleTests/TestsCGFloatArithmeticTesting.swift +++ b/TestsAndSample/TestsAndSampleTests/TestsCGFloatArithmeticTesting.swift @@ -17,15 +17,61 @@ class TestsCGFloatArithmeticTesting: SuperTestsScalarArithmetic, ScalarArithmeti self.assignmentValue = self.cgFloatValue + self.intValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue + self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue + self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue + self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue + self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue + self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue + self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) } func testAdditionAssignment() { self.expectedValue = 6.0 + + self.assignmentValue = 1.0 + self.assignmentValue += self.doubleValue + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.assignmentValue = 1.0 - self.assignmentValue += self.intValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.assignmentValue = 1.0 + self.assignmentValue += self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue += self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue += self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue += self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue += self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue += self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + } func testSubtraction() { @@ -37,15 +83,59 @@ class TestsCGFloatArithmeticTesting: SuperTestsScalarArithmetic, ScalarArithmeti self.assignmentValue = self.cgFloatValue - self.intValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.assignmentValue = self.cgFloatValue - self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue - self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue - self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue - self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue - self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue - self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) } + func testSubtractionAssignment() { self.expectedValue = -4.0 + self.assignmentValue = 1.0 - self.assignmentValue -= self.cgFloatValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue -= self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue -= self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue -= self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue -= self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue -= self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue -= self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + } @@ -58,16 +148,59 @@ class TestsCGFloatArithmeticTesting: SuperTestsScalarArithmetic, ScalarArithmeti self.assignmentValue = self.cgFloatValue * self.intValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.assignmentValue = self.cgFloatValue * self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue * self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue * self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue * self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue * self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue * self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + } func testMultiplicationAssignment() { self.expectedValue = 10.0 + self.assignmentValue = 2.0 - self.assignmentValue *= self.cgFloatValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.assignmentValue = 2.0 + self.assignmentValue *= self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 2.0 + self.assignmentValue *= self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 2.0 + self.assignmentValue *= self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 2.0 + self.assignmentValue *= self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 2.0 + self.assignmentValue *= self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 2.0 + self.assignmentValue *= self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + } func testDivision() { self.expectedValue = 1.0 @@ -78,15 +211,57 @@ class TestsCGFloatArithmeticTesting: SuperTestsScalarArithmetic, ScalarArithmeti self.assignmentValue = self.cgFloatValue / self.intValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.assignmentValue = self.cgFloatValue / self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue / self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue / self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue / self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue / self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.cgFloatValue / self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + } func testDivisionAssignment() { self.expectedValue = 2.0 + self.assignmentValue = 10.0 - self.assignmentValue /= self.cgFloatValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.assignmentValue = 10.0 + self.assignmentValue /= self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 10.0 + self.assignmentValue /= self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 10.0 + self.assignmentValue /= self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 10.0 + self.assignmentValue /= self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 10.0 + self.assignmentValue /= self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 10.0 + self.assignmentValue /= self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + } diff --git a/TestsAndSample/TestsAndSampleTests/TestsCGFloatComparable.swift b/TestsAndSample/TestsAndSampleTests/TestsCGFloatComparable.swift index f014d51..2332d39 100644 --- a/TestsAndSample/TestsAndSampleTests/TestsCGFloatComparable.swift +++ b/TestsAndSample/TestsAndSampleTests/TestsCGFloatComparable.swift @@ -13,21 +13,46 @@ class TestsCGFloatComparable: SuperTestsScalarComparable, ScalarComparableTestin func testEqual() { XCTAssert(self.cgFloatValue == self.doubleValue); XCTAssert(self.cgFloatValue == self.intValue); - + XCTAssert(self.cgFloatValue == self.int16Value); + XCTAssert(self.cgFloatValue == self.int32Value); + XCTAssert(self.cgFloatValue == self.int64Value); + XCTAssert(self.cgFloatValue == self.uInt16Value); + XCTAssert(self.cgFloatValue == self.uInt16Value); + XCTAssert(self.cgFloatValue == self.uInt16Value); } + func testNotEqual() { XCTAssertFalse(self.cgFloatValue != self.doubleValue); XCTAssertFalse(self.cgFloatValue != self.intValue); + XCTAssertFalse(self.cgFloatValue != self.int16Value); + XCTAssertFalse(self.cgFloatValue != self.int32Value); + XCTAssertFalse(self.cgFloatValue != self.int64Value); + XCTAssertFalse(self.cgFloatValue != self.uInt16Value); + XCTAssertFalse(self.cgFloatValue != self.uInt16Value); + XCTAssertFalse(self.cgFloatValue != self.uInt16Value); + } func testLessThanOrEqual() { XCTAssert(self.cgFloatValue <= self.doubleValue); XCTAssert(self.cgFloatValue <= self.intValue); + XCTAssert(self.cgFloatValue <= self.int16Value); + XCTAssert(self.cgFloatValue <= self.int32Value); + XCTAssert(self.cgFloatValue <= self.int64Value); + XCTAssert(self.cgFloatValue <= self.uInt16Value); + XCTAssert(self.cgFloatValue <= self.uInt16Value); + XCTAssert(self.cgFloatValue <= self.uInt16Value); self.cgFloatValue = -1 XCTAssert(self.cgFloatValue <= self.doubleValue); XCTAssert(self.cgFloatValue <= self.intValue); - + XCTAssert(self.cgFloatValue <= self.int16Value); + XCTAssert(self.cgFloatValue <= self.int32Value); + XCTAssert(self.cgFloatValue <= self.int64Value); + XCTAssert(self.cgFloatValue <= self.uInt16Value); + XCTAssert(self.cgFloatValue <= self.uInt16Value); + XCTAssert(self.cgFloatValue <= self.uInt16Value); + } @@ -35,6 +60,13 @@ class TestsCGFloatComparable: SuperTestsScalarComparable, ScalarComparableTestin self.cgFloatValue = -1 XCTAssert(self.cgFloatValue < self.doubleValue); XCTAssert(self.cgFloatValue < self.intValue); + XCTAssert(self.cgFloatValue < self.int16Value); + XCTAssert(self.cgFloatValue < self.int32Value); + XCTAssert(self.cgFloatValue < self.int64Value); + XCTAssert(self.cgFloatValue < self.uInt16Value); + XCTAssert(self.cgFloatValue < self.uInt16Value); + XCTAssert(self.cgFloatValue < self.uInt16Value); + } @@ -42,10 +74,24 @@ class TestsCGFloatComparable: SuperTestsScalarComparable, ScalarComparableTestin XCTAssert(self.cgFloatValue >= self.doubleValue); XCTAssert(self.cgFloatValue >= self.intValue); + XCTAssert(self.cgFloatValue >= self.int16Value); + XCTAssert(self.cgFloatValue >= self.int32Value); + XCTAssert(self.cgFloatValue >= self.int64Value); + XCTAssert(self.cgFloatValue >= self.uInt16Value); + XCTAssert(self.cgFloatValue >= self.uInt16Value); + XCTAssert(self.cgFloatValue >= self.uInt16Value); + self.cgFloatValue = -1 XCTAssertFalse(self.cgFloatValue >= self.doubleValue); XCTAssertFalse(self.cgFloatValue >= self.intValue); + XCTAssertFalse(self.cgFloatValue >= self.int16Value); + XCTAssertFalse(self.cgFloatValue >= self.int32Value); + XCTAssertFalse(self.cgFloatValue >= self.int64Value); + XCTAssertFalse(self.cgFloatValue >= self.uInt16Value); + XCTAssertFalse(self.cgFloatValue >= self.uInt16Value); + XCTAssertFalse(self.cgFloatValue >= self.uInt16Value); + } @@ -54,6 +100,13 @@ class TestsCGFloatComparable: SuperTestsScalarComparable, ScalarComparableTestin self.cgFloatValue = -1 XCTAssertFalse(self.cgFloatValue > self.doubleValue); XCTAssertFalse(self.cgFloatValue > self.intValue); + XCTAssertFalse(self.cgFloatValue > self.int16Value); + XCTAssertFalse(self.cgFloatValue > self.int32Value); + XCTAssertFalse(self.cgFloatValue > self.int64Value); + XCTAssertFalse(self.cgFloatValue > self.uInt16Value); + XCTAssertFalse(self.cgFloatValue > self.uInt16Value); + XCTAssertFalse(self.cgFloatValue > self.uInt16Value); + } diff --git a/TestsAndSample/TestsAndSampleTests/TestsCGFloatFunctions.swift b/TestsAndSample/TestsAndSampleTests/TestsCGFloatFunctions.swift deleted file mode 100644 index ab09a05..0000000 --- a/TestsAndSample/TestsAndSampleTests/TestsCGFloatFunctions.swift +++ /dev/null @@ -1,76 +0,0 @@ -// -// TestsCGFloat.swift -// TestsAndSample -// -// Created by Seivan Heidari on 29/06/14. -// Copyright (c) 2014 Seivan Heidari. All rights reserved. -// - -import XCTest -import CoreGraphics - -class TestsCGFloat: XCTestCase { - let doubleValue:CGFloat = 5.5 - var expected:CGFloat? - let additionalValue = 7.7 - - -#if !(arch(x86_64) || arch(arm64)) - func testAcos() { - self.expected = acosf(self.doubleValue) - XCTAssertEqualObjects(self.expected!, CGFloat(self.doubleValue.acos)) - } - func testAsin() { - self.expected = asinf(self.doubleValue) - XCTAssertEqualObjects(self.expected!, self.doubleValue.asin) - } - func testAtan() { - self.expected = atanf(self.doubleValue) - XCTAssertEqualObjects(self.expected!, CGFloat(self.doubleValue.atan)) - } - func testAtan2() { - self.expected = atan2f(self.doubleValue, CGFloat(self.additionalValue)) - XCTAssertEqualObjects(self.expected!, CGFloat(self.doubleValue.atan2(self.additionalValue))) - } - func testCos() { - self.expected = cosf(self.doubleValue) - XCTAssertEqualObjects(self.expected!, CGFloat(self.doubleValue.cos)) - } - func testSin() { - self.expected = sinf(self.doubleValue) - XCTAssertEqualObjects(self.expected!, CGFloat(self.doubleValue.sin)) - } - func testTan() { - self.expected = tanf(self.doubleValue) - XCTAssertEqualObjects(self.expected!, CGFloat(self.doubleValue.tan)) - } - func testExp() { - self.expected = expf(self.doubleValue) - XCTAssertEqualObjects(self.expected!, CGFloat(self.doubleValue.exp)) - } - func testExp2() { - self.expected = exp2f(self.doubleValue) - XCTAssertEqualObjects(self.expected!, CGFloat(self.doubleValue.exp2)) - } - func testLog() { - self.expected = logf(self.doubleValue) - XCTAssertEqualObjects(self.expected!, CGFloat(self.doubleValue.log)) - } - func testLog10() { - self.expected = log10f(self.doubleValue) - XCTAssertEqualObjects(self.expected!, CGFloat(self.doubleValue.log10)) - } - func testLog2() { - self.expected = log2f(self.doubleValue) - XCTAssertEqualObjects(self.expected!, CGFloat(self.doubleValue.log2)) - } -// func testPow() { -// self.expected = powf(self.doubleValue, CGFloat(self.additionalValue)) -// XCTAssertEqualObjects(Double(self.expected!), (self.doubleValue.pow(self.additionalValue))) -// } - func testSqrt() { - self.expected = sqrtf(self.doubleValue) - XCTAssertEqualObjects(self.expected!, CGFloat(self.doubleValue.sqrt)) - } -#endif -} diff --git a/TestsAndSample/TestsAndSampleTests/TestsDoubleArithmeticTesting.swift b/TestsAndSample/TestsAndSampleTests/TestsDoubleArithmeticTesting.swift index 2c108a6..bec8a6f 100644 --- a/TestsAndSample/TestsAndSampleTests/TestsDoubleArithmeticTesting.swift +++ b/TestsAndSample/TestsAndSampleTests/TestsDoubleArithmeticTesting.swift @@ -18,15 +18,62 @@ class TestsDoubleArithmeticTesting: SuperTestsScalarArithmetic, ScalarArithmetic self.assignmentValue = self.doubleValue + self.intValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue + self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue + self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue + self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue + self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue + self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.assignmentValue = self.doubleValue + self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + } func testAdditionAssignment() { self.expectedValue = 6.0 + self.assignmentValue = 1.0 - - self.assignmentValue += self.doubleValue + self.assignmentValue += self.cgFloatValue + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue += self.intValue + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue += self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue += self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue += self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue += self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue += self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue += self.uInt64Value XCTAssertEqual(self.assignmentValue, self.expectedValue!) + } @@ -40,12 +87,55 @@ class TestsDoubleArithmeticTesting: SuperTestsScalarArithmetic, ScalarArithmetic self.assignmentValue = self.doubleValue - self.intValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.assignmentValue = self.doubleValue - self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue - self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue - self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue - self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue - self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue - self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + } func testSubtractionAssignment() { self.expectedValue = -4.0 self.assignmentValue = 1.0 - self.assignmentValue -= self.doubleValue + self.assignmentValue -= self.cgFloatValue + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue -= self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue -= self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue -= self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue -= self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue -= self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1.0 + self.assignmentValue -= self.uInt64Value XCTAssertEqual(self.assignmentValue, self.expectedValue!) } @@ -58,13 +148,61 @@ class TestsDoubleArithmeticTesting: SuperTestsScalarArithmetic, ScalarArithmetic self.assignmentValue = self.doubleValue * self.intValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + + self.assignmentValue = self.doubleValue * self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue * self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue * self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue * self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue * self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue * self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + } func testMultiplicationAssignment() { self.expectedValue = 10.0 + + self.assignmentValue = 2.0 + self.assignmentValue *= self.cgFloatValue + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 2.0 + self.assignmentValue *= self.intValue + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.assignmentValue = 2.0 + self.assignmentValue *= self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) - self.assignmentValue *= self.doubleValue + self.assignmentValue = 2.0 + self.assignmentValue *= self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 2.0 + self.assignmentValue *= self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 2.0 + self.assignmentValue *= self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 2.0 + self.assignmentValue *= self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 2.0 + self.assignmentValue *= self.uInt64Value XCTAssertEqual(self.assignmentValue, self.expectedValue!) } @@ -77,14 +215,62 @@ class TestsDoubleArithmeticTesting: SuperTestsScalarArithmetic, ScalarArithmetic self.assignmentValue = self.doubleValue / self.intValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.assignmentValue = self.doubleValue / self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue / self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue / self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue / self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue / self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = self.doubleValue / self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + } func testDivisionAssignment() { self.expectedValue = 2.0 self.assignmentValue = 10.0 - self.assignmentValue /= self.doubleValue + self.assignmentValue /= self.cgFloatValue + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 10.0 + self.assignmentValue /= self.intValue + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 10.0 + self.assignmentValue /= self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 10.0 + self.assignmentValue /= self.int32Value XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.assignmentValue = 10.0 + self.assignmentValue /= self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 10.0 + self.assignmentValue /= self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 10.0 + self.assignmentValue /= self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 10.0 + self.assignmentValue /= self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + } diff --git a/TestsAndSample/TestsAndSampleTests/TestsDoubleComparable.swift b/TestsAndSample/TestsAndSampleTests/TestsDoubleComparable.swift index 9a0cfd0..6a1f5bf 100644 --- a/TestsAndSample/TestsAndSampleTests/TestsDoubleComparable.swift +++ b/TestsAndSample/TestsAndSampleTests/TestsDoubleComparable.swift @@ -13,20 +13,46 @@ class TestsDoubleComparable: SuperTestsScalarComparable, ScalarComparableTesting func testEqual() { XCTAssert(self.doubleValue == self.intValue); XCTAssert(self.doubleValue == self.cgFloatValue); + XCTAssert(self.doubleValue == self.int16Value); + XCTAssert(self.doubleValue == self.int32Value); + XCTAssert(self.doubleValue == self.int64Value); + XCTAssert(self.doubleValue == self.uInt16Value); + XCTAssert(self.doubleValue == self.uInt16Value); + XCTAssert(self.doubleValue == self.uInt16Value); + } func testNotEqual() { XCTAssertFalse(self.doubleValue != self.intValue); XCTAssertFalse(self.doubleValue != self.cgFloatValue); + XCTAssertFalse(self.doubleValue != self.int16Value); + XCTAssertFalse(self.doubleValue != self.int32Value); + XCTAssertFalse(self.doubleValue != self.int64Value); + XCTAssertFalse(self.doubleValue != self.uInt16Value); + XCTAssertFalse(self.doubleValue != self.uInt16Value); + XCTAssertFalse(self.doubleValue != self.uInt16Value); + } func testLessThanOrEqual() { XCTAssert(self.doubleValue <= self.intValue); XCTAssert(self.doubleValue <= self.cgFloatValue); + XCTAssert(self.doubleValue <= self.int16Value); + XCTAssert(self.doubleValue <= self.int32Value); + XCTAssert(self.doubleValue <= self.int64Value); + XCTAssert(self.doubleValue <= self.uInt16Value); + XCTAssert(self.doubleValue <= self.uInt16Value); + XCTAssert(self.doubleValue <= self.uInt16Value); self.doubleValue = -1 XCTAssert(self.doubleValue <= self.intValue); XCTAssert(self.doubleValue <= self.cgFloatValue); + XCTAssert(self.doubleValue <= self.int16Value); + XCTAssert(self.doubleValue <= self.int32Value); + XCTAssert(self.doubleValue <= self.int64Value); + XCTAssert(self.doubleValue <= self.uInt16Value); + XCTAssert(self.doubleValue <= self.uInt16Value); + XCTAssert(self.doubleValue <= self.uInt16Value); @@ -35,6 +61,13 @@ class TestsDoubleComparable: SuperTestsScalarComparable, ScalarComparableTesting self.doubleValue = -1 XCTAssert(self.doubleValue < self.intValue); XCTAssert(self.doubleValue < self.cgFloatValue); + XCTAssert(self.doubleValue < self.int16Value); + XCTAssert(self.doubleValue < self.int32Value); + XCTAssert(self.doubleValue < self.int64Value); + XCTAssert(self.doubleValue < self.uInt16Value); + XCTAssert(self.doubleValue < self.uInt16Value); + XCTAssert(self.doubleValue < self.uInt16Value); + } @@ -42,10 +75,24 @@ class TestsDoubleComparable: SuperTestsScalarComparable, ScalarComparableTesting XCTAssert(self.doubleValue >= self.intValue); XCTAssert(self.doubleValue >= self.cgFloatValue); + XCTAssert(self.doubleValue >= self.int16Value); + XCTAssert(self.doubleValue >= self.int32Value); + XCTAssert(self.doubleValue >= self.int64Value); + XCTAssert(self.doubleValue >= self.uInt16Value); + XCTAssert(self.doubleValue >= self.uInt16Value); + XCTAssert(self.doubleValue >= self.uInt16Value); + self.doubleValue = -1 XCTAssertFalse(self.doubleValue >= self.intValue); XCTAssertFalse(self.doubleValue >= self.cgFloatValue); + XCTAssertFalse(self.doubleValue >= self.int16Value); + XCTAssertFalse(self.doubleValue >= self.int32Value); + XCTAssertFalse(self.doubleValue >= self.int64Value); + XCTAssertFalse(self.doubleValue >= self.uInt16Value); + XCTAssertFalse(self.doubleValue >= self.uInt16Value); + XCTAssertFalse(self.doubleValue >= self.uInt16Value); + } func testGreaterThan() { @@ -53,6 +100,13 @@ class TestsDoubleComparable: SuperTestsScalarComparable, ScalarComparableTesting self.doubleValue = -1 XCTAssertFalse(self.doubleValue > self.intValue); XCTAssertFalse(self.doubleValue > self.cgFloatValue); + XCTAssertFalse(self.doubleValue > self.int16Value); + XCTAssertFalse(self.doubleValue > self.int32Value); + XCTAssertFalse(self.doubleValue > self.int64Value); + XCTAssertFalse(self.doubleValue > self.uInt16Value); + XCTAssertFalse(self.doubleValue > self.uInt16Value); + XCTAssertFalse(self.doubleValue > self.uInt16Value); + } diff --git a/TestsAndSample/TestsAndSampleTests/TestsDoubleFunctions.swift b/TestsAndSample/TestsAndSampleTests/TestsDoubleFunctions.swift deleted file mode 100644 index d6ad2ef..0000000 --- a/TestsAndSample/TestsAndSampleTests/TestsDoubleFunctions.swift +++ /dev/null @@ -1,78 +0,0 @@ -// -// TestsAndSampleTests.swift -// TestsAndSampleTests -// -// Created by Seivan Heidari on 29/06/14. -// Copyright (c) 2014 Seivan Heidari. All rights reserved. -// - -import XCTest - - -class TestsDouble: XCTestCase { - let doubleValue = 5.5 - var expected:Double? - let additionalValue = 7.7 - - - - func testAcos() { - self.expected = acos(self.doubleValue) - XCTAssertEqualObjects(self.expected!, self.doubleValue.acos) - } - func testAsin() { - self.expected = asin(self.doubleValue) - XCTAssertEqualObjects(self.expected!, self.doubleValue.asin) - } - func testAtan() { - self.expected = atan(self.doubleValue) - XCTAssertEqualObjects(self.expected!, self.doubleValue.atan) - } - func testAtan2() { - self.expected = atan2(self.doubleValue, self.additionalValue) - XCTAssertEqualObjects(self.expected!, self.doubleValue.atan2(self.additionalValue)) - } - func testCos() { - self.expected = cos(self.doubleValue) - XCTAssertEqualObjects(self.expected!, self.doubleValue.cos) - } - func testSin() { - self.expected = sin(self.doubleValue) - XCTAssertEqualObjects(self.expected!, self.doubleValue.sin) - } - func testTan() { - self.expected = tan(self.doubleValue) - XCTAssertEqualObjects(self.expected!, self.doubleValue.tan) - } - func testExp() { - self.expected = exp(self.doubleValue) - XCTAssertEqualObjects(self.expected!, self.doubleValue.exp) - } - func testExp2() { - self.expected = exp2(self.doubleValue) - XCTAssertEqualObjects(self.expected!, self.doubleValue.exp2) - } - func testLog() { - self.expected = log(self.doubleValue) - XCTAssertEqualObjects(self.expected!, self.doubleValue.log) - } - func testLog10() { - self.expected = log10(self.doubleValue) - XCTAssertEqualObjects(self.expected!, self.doubleValue.log10) - } - func testLog2() { - self.expected = log2(self.doubleValue) - XCTAssertEqualObjects(self.expected!, self.doubleValue.log2) - } - func testPow() { - self.expected = pow(self.doubleValue, self.additionalValue) - XCTAssertEqualObjects(self.expected!, self.doubleValue.pow(self.additionalValue)) - } - func testSqrt() { - self.expected = sqrt(self.doubleValue) - XCTAssertEqualObjects(self.expected!, self.doubleValue.sqrt) - } - -} - - diff --git a/TestsAndSample/TestsAndSampleTests/TestsIntArithmeticTesting.swift b/TestsAndSample/TestsAndSampleTests/TestsIntArithmeticTesting.swift index 8f0aedb..5d64a19 100644 --- a/TestsAndSample/TestsAndSampleTests/TestsIntArithmeticTesting.swift +++ b/TestsAndSample/TestsAndSampleTests/TestsIntArithmeticTesting.swift @@ -9,43 +9,152 @@ import XCTest class TestsIntArithmeticTesting: SuperTestsScalarArithmetic, ScalarArithmeticTesting { + var assignmentIntValue:Int = Int(0) + var expectedIntValue:Int? + func testAddition() { self.expectedValue = 10.0 + self.assignmentValue = self.intValue + self.doubleValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) self.assignmentValue = self.intValue + self.cgFloatValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.expectedIntValue = 10 + + self.assignmentIntValue = self.intValue + self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue + self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue + self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue + self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue + self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue + self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + + } func testAdditionAssignment() { self.expectedValue = 6.0 - self.assignmentValue = 1.0 - + + self.assignmentValue = 1 + self.assignmentValue += self.doubleValue + XCTAssertEqual(self.assignmentValue, self.expectedValue!) + + self.assignmentValue = 1 self.assignmentValue += self.cgFloatValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.expectedIntValue = 6 + + self.assignmentIntValue = 1 + self.assignmentIntValue += self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 1 + self.assignmentIntValue += self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 1 + self.assignmentIntValue += self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 1 + self.assignmentIntValue += self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 1 + self.assignmentIntValue += self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 1 + self.assignmentIntValue += self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + + + } func testSubtraction() { self.expectedValue = 0.0 - + self.assignmentValue = self.intValue - self.doubleValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) self.assignmentValue = self.intValue - self.cgFloatValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.expectedIntValue = 0 + + self.assignmentIntValue = self.intValue - self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue - self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue - self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue - self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue - self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue - self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + } func testSubtractionAssignment() { self.expectedValue = -4.0 + self.assignmentValue = 1.0 - self.assignmentValue -= self.intValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.expectedIntValue = -4 + + self.assignmentIntValue = 1 + self.assignmentIntValue -= self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 1 + self.assignmentIntValue -= self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 1 + self.assignmentIntValue -= self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 1 + self.assignmentIntValue -= self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 1 + self.assignmentIntValue -= self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 1 + self.assignmentIntValue -= self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + + } @@ -58,15 +167,63 @@ class TestsIntArithmeticTesting: SuperTestsScalarArithmetic, ScalarArithmeticTes self.assignmentValue = self.intValue * self.cgFloatValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.expectedIntValue = 25 + self.assignmentIntValue = self.intValue * self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue * self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue * self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue * self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue * self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue * self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + + + } func testMultiplicationAssignment() { self.expectedValue = 10.0 + self.assignmentValue = 2.0 - self.assignmentValue *= self.intValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.expectedIntValue = 10 + + self.assignmentIntValue = 2 + self.assignmentIntValue *= self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 2 + self.assignmentIntValue *= self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 2 + self.assignmentIntValue *= self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 2 + self.assignmentIntValue *= self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 2 + self.assignmentIntValue *= self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 2 + self.assignmentIntValue *= self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + } func testDivision() { @@ -78,15 +235,60 @@ class TestsIntArithmeticTesting: SuperTestsScalarArithmetic, ScalarArithmeticTes self.assignmentValue = self.intValue / self.cgFloatValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.expectedIntValue = 1 + self.assignmentIntValue = self.intValue / self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue / self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue / self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue / self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue / self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = self.intValue / self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + } func testDivisionAssignment() { self.expectedValue = 2.0 + self.assignmentValue = 10.0 - self.assignmentValue /= self.intValue XCTAssertEqual(self.assignmentValue, self.expectedValue!) + self.expectedIntValue = 2 + + self.assignmentIntValue = 10 + self.assignmentIntValue /= self.int16Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 10 + self.assignmentIntValue /= self.int32Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 10 + self.assignmentIntValue /= self.int64Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 10 + self.assignmentIntValue /= self.uInt16Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 10 + self.assignmentIntValue /= self.uInt32Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + + self.assignmentIntValue = 10 + self.assignmentIntValue /= self.uInt64Value + XCTAssertEqual(self.assignmentValue, self.expectedIntValue!) + } diff --git a/TestsAndSample/TestsAndSampleTests/TestsIntComparable.swift b/TestsAndSample/TestsAndSampleTests/TestsIntComparable.swift index 607a2e5..a715e65 100644 --- a/TestsAndSample/TestsAndSampleTests/TestsIntComparable.swift +++ b/TestsAndSample/TestsAndSampleTests/TestsIntComparable.swift @@ -13,20 +13,48 @@ class TestsIntComparable: SuperTestsScalarComparable, ScalarComparableTesting { func testEqual() { XCTAssert(self.intValue == self.doubleValue); XCTAssert(self.intValue == self.cgFloatValue); + XCTAssert(self.intValue == self.int16Value); + XCTAssert(self.intValue == self.int32Value); + XCTAssert(self.intValue == self.int64Value); + XCTAssert(self.intValue == self.uInt16Value); + XCTAssert(self.intValue == self.uInt16Value); + XCTAssert(self.intValue == self.uInt16Value); + } func testNotEqual() { XCTAssertFalse(self.intValue != self.doubleValue); XCTAssertFalse(self.intValue != self.cgFloatValue); + XCTAssertFalse(self.intValue != self.int16Value); + XCTAssertFalse(self.intValue != self.int32Value); + XCTAssertFalse(self.intValue != self.int64Value); + XCTAssertFalse(self.intValue != self.uInt16Value); + XCTAssertFalse(self.intValue != self.uInt16Value); + XCTAssertFalse(self.intValue != self.uInt16Value); + } func testLessThanOrEqual() { XCTAssert(self.intValue <= self.doubleValue); XCTAssert(self.intValue <= self.cgFloatValue); + XCTAssert(self.intValue <= self.int16Value); + XCTAssert(self.intValue <= self.int32Value); + XCTAssert(self.intValue <= self.int64Value); + XCTAssert(self.intValue <= self.uInt16Value); + XCTAssert(self.intValue <= self.uInt16Value); + XCTAssert(self.intValue <= self.uInt16Value); + self.intValue = -1 XCTAssert(self.intValue <= self.doubleValue); XCTAssert(self.intValue <= self.cgFloatValue); + XCTAssert(self.intValue <= self.int16Value); + XCTAssert(self.intValue <= self.int32Value); + XCTAssert(self.intValue <= self.int64Value); + XCTAssert(self.intValue <= self.uInt16Value); + XCTAssert(self.intValue <= self.uInt16Value); + XCTAssert(self.intValue <= self.uInt16Value); + } @@ -34,6 +62,13 @@ class TestsIntComparable: SuperTestsScalarComparable, ScalarComparableTesting { self.intValue = -1 XCTAssert(self.intValue < self.doubleValue); XCTAssert(self.intValue < self.cgFloatValue); + XCTAssert(self.intValue < self.int16Value); + XCTAssert(self.intValue < self.int32Value); + XCTAssert(self.intValue < self.int64Value); + XCTAssert(self.intValue < self.uInt16Value); + XCTAssert(self.intValue < self.uInt16Value); + XCTAssert(self.intValue < self.uInt16Value); + } @@ -41,10 +76,24 @@ class TestsIntComparable: SuperTestsScalarComparable, ScalarComparableTesting { XCTAssert(self.intValue >= self.doubleValue); XCTAssert(self.intValue >= self.cgFloatValue); + XCTAssert(self.intValue >= self.int16Value); + XCTAssert(self.intValue >= self.int32Value); + XCTAssert(self.intValue >= self.int64Value); + XCTAssert(self.intValue >= self.uInt16Value); + XCTAssert(self.intValue >= self.uInt16Value); + XCTAssert(self.intValue >= self.uInt16Value); + self.intValue = -1 XCTAssertFalse(self.intValue >= self.doubleValue); XCTAssertFalse(self.intValue >= self.cgFloatValue); + XCTAssertFalse(self.intValue >= self.int16Value); + XCTAssertFalse(self.intValue >= self.int32Value); + XCTAssertFalse(self.intValue >= self.int64Value); + XCTAssertFalse(self.intValue >= self.uInt16Value); + XCTAssertFalse(self.intValue >= self.uInt16Value); + XCTAssertFalse(self.intValue >= self.uInt16Value); + } @@ -52,6 +101,13 @@ class TestsIntComparable: SuperTestsScalarComparable, ScalarComparableTesting { self.intValue = -1 XCTAssertFalse(self.intValue > self.doubleValue); XCTAssertFalse(self.intValue > self.cgFloatValue); + XCTAssertFalse(self.intValue > self.int16Value); + XCTAssertFalse(self.intValue > self.int32Value); + XCTAssertFalse(self.intValue > self.int64Value); + XCTAssertFalse(self.intValue > self.uInt16Value); + XCTAssertFalse(self.intValue > self.uInt16Value); + XCTAssertFalse(self.intValue > self.uInt16Value); + }