diff --git a/Math/Math.xcodeproj/project.pbxproj b/Math/Math.xcodeproj/project.pbxproj index 650bf7c..6f40c13 100644 --- a/Math/Math.xcodeproj/project.pbxproj +++ b/Math/Math.xcodeproj/project.pbxproj @@ -11,9 +11,11 @@ C005E0051BE1CBA800F1BD3C /* Math.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C005DFFA1BE1CBA700F1BD3C /* Math.framework */; }; C005E00A1BE1CBA800F1BD3C /* MatrixTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C005E0091BE1CBA800F1BD3C /* MatrixTests.swift */; }; C005E0391BE1CC7A00F1BD3C /* Matrix.swift in Sources */ = {isa = PBXBuildFile; fileRef = C005E0381BE1CC7A00F1BD3C /* Matrix.swift */; }; + C0211EF01BF59F29006936E7 /* VectorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0211EEF1BF59F29006936E7 /* VectorTests.swift */; }; C04449C11BE26A0700ABF046 /* Vector.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04449C01BE26A0700ABF046 /* Vector.swift */; }; C08C72021BED07BB0030AD52 /* MatrixFunctionalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C08C72011BED07BB0030AD52 /* MatrixFunctionalTests.swift */; }; C08C72041BED08900030AD52 /* Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = C08C72031BED08900030AD52 /* Types.swift */; }; + C08C72061BF0F33A0030AD52 /* TypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C08C72051BF0F33A0030AD52 /* TypeTests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -34,9 +36,11 @@ C005E0091BE1CBA800F1BD3C /* MatrixTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatrixTests.swift; sourceTree = ""; }; C005E00B1BE1CBA800F1BD3C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; C005E0381BE1CC7A00F1BD3C /* Matrix.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Matrix.swift; sourceTree = ""; }; + C0211EEF1BF59F29006936E7 /* VectorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VectorTests.swift; sourceTree = ""; }; C04449C01BE26A0700ABF046 /* Vector.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Vector.swift; sourceTree = ""; }; C08C72011BED07BB0030AD52 /* MatrixFunctionalTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MatrixFunctionalTests.swift; sourceTree = ""; }; C08C72031BED08900030AD52 /* Types.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Types.swift; sourceTree = ""; }; + C08C72051BF0F33A0030AD52 /* TypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeTests.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -93,6 +97,8 @@ children = ( C005E0091BE1CBA800F1BD3C /* MatrixTests.swift */, C08C72011BED07BB0030AD52 /* MatrixFunctionalTests.swift */, + C08C72051BF0F33A0030AD52 /* TypeTests.swift */, + C0211EEF1BF59F29006936E7 /* VectorTests.swift */, C005E00B1BE1CBA800F1BD3C /* Info.plist */, ); path = MathTests; @@ -216,7 +222,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + C08C72061BF0F33A0030AD52 /* TypeTests.swift in Sources */, C005E00A1BE1CBA800F1BD3C /* MatrixTests.swift in Sources */, + C0211EF01BF59F29006936E7 /* VectorTests.swift in Sources */, C08C72021BED07BB0030AD52 /* MatrixFunctionalTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Math/MathTests/MatrixFunctionalTests.swift b/Math/MathTests/MatrixFunctionalTests.swift index c28d2e2..ccec6e1 100644 --- a/Math/MathTests/MatrixFunctionalTests.swift +++ b/Math/MathTests/MatrixFunctionalTests.swift @@ -8,7 +8,23 @@ import Foundation import XCTest +@testable import Math + +func assertVectorAlmostEqual(@autoclosure lhs: () -> T?, @autoclosure _ rhs: () -> T?, message: String = "", file: String = __FILE__, line: UInt = __LINE__) { + let lhsValue = lhs() + let rhsValue = rhs() + let msg = message != "" ? message : "expected \(lhsValue), got \(rhsValue)" + XCTAssert(lhsValue ==~ rhsValue, msg, file: file, line: line) +} class MatrixVectorTests: XCTestCase { - func + func testThatMultiplyingIdentityByAVectorGivesTheVector() { + let v = Matrix4.identity * Vector4(x: 1, y: 2, z: 3) + assertVectorAlmostEqual(v, Vector4(x: 1, y: 2, z: 3)) + } + + func testThatMultiplyingTranslationByAVectorGivesTranslatedVector() { + let v = Matrix4(translationWithX: 1, y: 1, z: 1) * Vector4(x: 2, y: 2, z: 2) + assertVectorAlmostEqual(v, Vector4(x: 3, y: 3, z: 3)) + } } \ No newline at end of file diff --git a/Math/MathTests/TypeTests.swift b/Math/MathTests/TypeTests.swift new file mode 100644 index 0000000..4e80839 --- /dev/null +++ b/Math/MathTests/TypeTests.swift @@ -0,0 +1,10 @@ +// +// TypeTests.swift +// Math +// +// Created by Eryn Wells on 11/9/15. +// Copyright © 2015 Eryn Wells. All rights reserved. +// + +import Foundation +import Math \ No newline at end of file diff --git a/Math/MathTests/VectorTests.swift b/Math/MathTests/VectorTests.swift new file mode 100644 index 0000000..a58fc9d --- /dev/null +++ b/Math/MathTests/VectorTests.swift @@ -0,0 +1,24 @@ +// +// VectorTests.swift +// Math +// +// Created by Eryn Wells on 11/12/15. +// Copyright © 2015 Eryn Wells. All rights reserved. +// + +import XCTest +@testable import Math + +class VectorTests: XCTestCase { + func testThatLengthOfAUnitVectorIsSane() { + XCTAssertEqualWithAccuracy(Vector3(x: 1, y: 0, z: 0).length, 1.0, accuracy: Float.Epsilon) + } + + func testThatTheLength2OfAVectorIsSane() { + XCTAssertEqualWithAccuracy(Vector3(x: 2, y: 0, z: 0).length2, 4.0, accuracy: Float.Epsilon) + } + + func testThatANormalizedVectorHasLength1() { + XCTAssertEqualWithAccuracy(Vector3(x: 1, y: 2, z: 3).normalized.length, 1.0, accuracy: 1e-6) + } +} \ No newline at end of file