[Math] Some basic Vector tests
This commit is contained in:
		
							parent
							
								
									58dfb3f787
								
							
						
					
					
						commit
						23bbdac76a
					
				
					 4 changed files with 59 additions and 1 deletions
				
			
		|  | @ -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 = "<group>"; }; | ||||
| 		C005E00B1BE1CBA800F1BD3C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; | ||||
| 		C005E0381BE1CC7A00F1BD3C /* Matrix.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Matrix.swift; sourceTree = "<group>"; }; | ||||
| 		C0211EEF1BF59F29006936E7 /* VectorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VectorTests.swift; sourceTree = "<group>"; }; | ||||
| 		C04449C01BE26A0700ABF046 /* Vector.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Vector.swift; sourceTree = "<group>"; }; | ||||
| 		C08C72011BED07BB0030AD52 /* MatrixFunctionalTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MatrixFunctionalTests.swift; sourceTree = "<group>"; }; | ||||
| 		C08C72031BED08900030AD52 /* Types.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Types.swift; sourceTree = "<group>"; }; | ||||
| 		C08C72051BF0F33A0030AD52 /* TypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeTests.swift; sourceTree = "<group>"; }; | ||||
| /* 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; | ||||
|  |  | |||
|  | @ -8,7 +8,23 @@ | |||
| 
 | ||||
| import Foundation | ||||
| import XCTest | ||||
| @testable import Math | ||||
| 
 | ||||
| func assertVectorAlmostEqual<T: Vector>(@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)) | ||||
|     } | ||||
| } | ||||
							
								
								
									
										10
									
								
								Math/MathTests/TypeTests.swift
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								Math/MathTests/TypeTests.swift
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||
							
								
								
									
										24
									
								
								Math/MathTests/VectorTests.swift
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								Math/MathTests/VectorTests.swift
									
										
									
									
									
										Normal file
									
								
							|  | @ -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) | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue