Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UnitTestVector{
- V2<int> v2i{1, 2};
- V2<float> v2f{4.0, 5.0};
- V2d magtest{6.0, 8.0};
- V3d normtest{3., 2., 1.};
- // V2<double> v2d; --- not defined yet
- #define utv_test(title, cond) do{ \
- cout << "--- " << title << " ---" << endl; \
- cout << "Test: " << #cond << endl; \
- bool test_passed = true; \
- try{ \
- if(!(cond)) throw "Test: failed"; \
- } catch(const char* e){ \
- cout << e << endl; \
- test_passed = false; \
- } \
- if (test_passed) cout << "Test: passed" << endl; \
- }while(0);
- public:
- UnitTestVector(){
- utv_test("Test operatror[] integer vector", v2i[0] == 1);
- utv_test("Test y() integer vetor", v2i.y() == 2);
- utv_test("Test operator[] float vector", v2f[0] == 4.0);
- utv_test("Test y() float vector", v2f.y() == 5.0);
- // https://www.mathsisfun.com/algebra/vectors.html
- utv_test("Test magnitude", magtest.length() == 10.0);
- //http://www.fundza.com/vectors/normalize/
- normtest.normalize();
- V3d expnorm{0.802, 0.267, 0.534};
- utv_test("Test normalization", normtest.cmp_close(expnorm));
- }
- };
- /*** OUTPUT ***
- --- Test operatror[] integer vector ---
- Test: v2i[0] == 1
- Test: passed
- --- Test y() integer vetor ---
- Test: v2i.y() == 2
- Test: passed
- --- Test operator[] float vector ---
- Test: v2f[0] == 4.0
- Test: passed
- --- Test y() float vector ---
- Test: v2f.y() == 5.0
- Test: passed
- --- Test magnitude ---
- Test: magtest.length() == 10.0
- Test: passed
- --- Test normalization ---
- Test: normtest.cmp_close(expnorm)
- Test: passed
- ***/
Advertisement
Add Comment
Please, Sign In to add comment