summaryrefslogtreecommitdiff
path: root/src/vhctest/Vector3DTest.cc
blob: bf4203a4bbedee609f29b20fb9a3b97b85532e05 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
 * Vector3DTest.cc
 *
 *  Created on: Mar 1, 2011
 *      Author: Jakob Odersky
 */


#include <iostream>
#include <assert.h>
#include <iomanip>
#include <limits>
//TODO change relative include
#include "Vector3D.h"

using namespace std;
using namespace vhc;


bool printTest();

int main() {
	//equality test
	assert(Vector3D(1, 2, 3) == Vector3D(1, 2, 3));
	assert(Vector3D(1, 2.4, 3) != Vector3D(1, 2, 3));

	//addition test
	assert(Vector3D(1, -0.9, 57683) + Vector3D(-1, 0.9, -57683) == Vector3D::Null);

	//addition, mutliplication test
	assert(Vector3D(4, 0, 16) / 4 == -Vector3D(0.25, 0, 1) * -4);

	//length test
	assert(Vector3D(0,3,4).getNorm() == 5);

	bool caught = false;
	try {
		~Vector3D::Null;
	} catch (domain_error& ex) {
		caught = true;
	};
	assert(caught == true);

	cout << "Vector3D: tests completed successfully" << endl;

	return 0;
}

bool printTest() {
	cout << "PRINT TEST" << endl;
	cout << Vector3D(1,2,3) << endl;
	char answer;
	do {
		cout << "Was 'Vector3D(1,2,3)' displayed? (y/n)" << endl;
		cin >> answer;
	} while (answer != 'y' && answer != 'n');
	cout << "END PRINT TEST" << endl;

	if (answer == 'y') return true;
	else return false;
}