aboutsummaryrefslogtreecommitdiff
path: root/tests/vectorPositionDimension2d.cpp
blob: b6c108f2edaf473940266471c18522801150e020 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (C) 2008-2011 Colin MacDonald
// No rights reserved: this software is in the public domain.

/** This test verifies that position2d and vector2d are interchangeable,
	and that they can convert from dimension2d */

#include "testUtils.h"

using namespace irr;
using namespace core;


template <class DIMENSION, class VECTOR, class POSITION, class T>
static bool doTest(void)
{
	bool result = true;

	DIMENSION dimension((T)99.9, (T)99.9);
	VECTOR vector(dimension);
	POSITION position(vector);
	DIMENSION dimension2(vector);

	result &= (vector == position);
	result &= (vector == dimension); // The conversion should be explicit.
	result &= (dimension2 == position);
	result &= (position == POSITION((T)99.9, (T)99.9));
	assert(result);
	
	dimension = (T)2 * position;
	result &= (dimension == VECTOR(2 * (T)99.9, 2 * (T)99.9));
	assert(result);

	dimension /= (T)2;
	result &= (dimension == POSITION((T)99.9, (T)99.9));
	assert(result);

	dimension += vector;
	result &= (dimension == VECTOR(2 * (T)99.9, 2 * (T)99.9));
	assert(result);

	dimension -= position;
	result &= (dimension == POSITION((T)99.9, (T)99.9));
	assert(result);
	
	position = dimension;
	result &= (position == VECTOR((T)99.9, (T)99.9));
	assert(result);

	vector += position;
	result &= (vector == POSITION(2 * (T)99.9, 2 * (T)99.9));
	assert(result);

	vector -= position;
	result &= (vector == dimension);
	assert(result);

	position *= (T)3.5;
	result &= (position == VECTOR((T)3.5 * (T)99.9, (T)3.5 * (T)99.9));
	assert(result);

	vector += dimension;
	result &= (vector == VECTOR(2 * (T)99.9, 2 * (T)99.9));
	assert(result);

	return result;
}

bool vectorPositionDimension2d(void)
{
	bool result = true;

	logTestString("vector,position,dimension test with s32\n\n");
	result &= doTest<dimension2di, vector2di, position2di, s32>();
	if (result)
		logTestString("tests passed\n\n");
	else
		logTestString("\ntests failed\n\n");
	logTestString("vector,position,dimension test with f32\n\n");
	result &= doTest<dimension2df, vector2df, position2df, f32>();
	if (result)
		logTestString("tests passed\n\n");
	else
		logTestString("\ntests failed\n\n");
	logTestString("vector,position,dimension test with f64\n\n");
	result &= doTest<dimension2d<f64>, vector2d<f64>, position2d<f64>, f64>();
	if (result)
		logTestString("tests passed\n\n");
	else
		logTestString("\ntests failed\n\n");

	return result;
}