1 module doml.tests.vector_4d_test; 2 3 import std.stdio; 4 import Math = doml.math; 5 import doml.tests.dunit_tests; 6 7 import doml.vector_4d; 8 9 /* 10 * The MIT License 11 * 12 * Copyright (c) 2015-2021 JOML. 13 ^%$^ Translated by jordan4ibanez 14 * 15 * Permission is hereby granted, free of charge, to any person obtaining a copy 16 * of this software and associated documentation files (the "Software"), to deal 17 * in the Software without restriction, including without limitation the rights 18 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 19 * copies of the Software, and to permit persons to whom the Software is 20 * furnished to do so, subject to the following conditions: 21 * 22 * The above copyright notice and this permission notice shall be included in 23 * all copies or substantial portions of the Software. 24 * 25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 31 * THE SOFTWARE. 32 */ 33 34 /** 35 * Test class for {@link Vector4d}. 36 * @author Sebastian Fellner 37 */ 38 unittest { 39 40 writeln("\nBEGINNING VECTOR4D TESTING\n"); 41 42 43 writeln("TESTING ANGLE VECTOR4D TO VECTOR4D"); 44 45 { 46 Vector4d testVec1 = Vector4d(2, -9.37, 5.892, -12.5); 47 Vector4d testVec2 = Vector4d(); 48 49 // angle(v, v) should give 0 50 double angle = testVec1.angle(testVec1); 51 assertEquals(0, angle, MANY_OPS_AROUND_ZERO_PRECISION_DOUBLE); 52 53 // angle(v, -v) should give Math.PI 54 testVec1.negate(testVec2); 55 angle = testVec1.angle(testVec2); 56 assertEquals(Math.PI, angle, MANY_OPS_AROUND_ZERO_PRECISION_DOUBLE); 57 } 58 59 writeln("PASSED!"); 60 61 writeln("TESTING MULTIPLY BY SCALAR INTO DESTINATION"); 62 63 { 64 Vector4d testVec1 = Vector4d(2, 2, 2, 2); 65 Vector4d destVec = Vector4d(0, 0, 0, 0); 66 67 testVec1.mul(2, destVec); 68 assertEquals(Vector4d(4, 4, 4, 4), destVec); 69 assertEquals(Vector4d(2, 2, 2, 2), testVec1); 70 } 71 72 writeln("PASSED!"); 73 74 writeln("TESTING DIVIDE BY SCALAR INTO DESTINATION"); 75 76 { 77 Vector4d testVec1 = Vector4d(2, 2, 2, 2); 78 Vector4d destVec = Vector4d(0, 0, 0, 0); 79 80 testVec1.div(2, destVec); 81 assertEquals(Vector4d(1, 1, 1, 1), destVec); 82 assertEquals(Vector4d(2, 2, 2, 2), testVec1); 83 } 84 85 writeln("PASSED!"); 86 }