File: model_test.cpp

package info (click to toggle)
megaglest 3.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 12,904 kB
  • ctags: 18,215
  • sloc: cpp: 144,232; ansic: 11,860; sh: 2,949; perl: 1,899; python: 1,751; objc: 142; asm: 42; makefile: 24
file content (108 lines) | stat: -rw-r--r-- 3,494 bytes parent folder | download | duplicates (4)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// ==============================================================
//	This file is part of MegaGlest Unit Tests (www.megaglest.org)
//
//	Copyright (C) 2013 Mark Vejvoda
//
//	You can redistribute this code and/or modify it under
//	the terms of the GNU General Public License as published
//	by the Free Software Foundation; either version 2 of the
//	License, or (at your option) any later version
// ==============================================================

#include <cppunit/extensions/HelperMacros.h>
#include <memory>
#include "model.h"
#include <vector>
#include <algorithm>

#ifdef WIN32
#include <io.h>
#else
#include <unistd.h>
#endif

using namespace Shared::Graphics;

class TestBaseColorPickEntity : public BaseColorPickEntity {
public:
	virtual string getUniquePickName() const {
		return getColorDescription();
	}
};
//
// Tests for font class
//
class ModelTest : public CppUnit::TestFixture {
	// Register the suite of tests for this fixture
	CPPUNIT_TEST_SUITE( ModelTest );

	CPPUNIT_TEST( test_ColorPicking_loop );
	CPPUNIT_TEST( test_ColorPicking_prime );

	CPPUNIT_TEST_SUITE_END();
	// End of Fixture registration

public:

	void test_ColorPicking_loop() {

		BaseColorPickEntity::setTrackColorUse(true);
		BaseColorPickEntity::setUsingLoopMethod(true);
		BaseColorPickEntity::resetUniqueColors();

		TestBaseColorPickEntity colorPicker;
		// This is the max color count this algorithm supports
		const int unsigned MAX_SUPPORTED_COLORS_USING_THIS_METHOD = 32767;
		for(unsigned int i = 0; i < MAX_SUPPORTED_COLORS_USING_THIS_METHOD; ++i) {
			bool duplicate = colorPicker.get_next_assign_color(colorPicker.getUniqueColorID());
			CPPUNIT_ASSERT_EQUAL( false,duplicate );
		}

		BaseColorPickEntity::resetUniqueColors();

		TestBaseColorPickEntity colorPicker2;
		// This is a test to prove when the algorithm fails
		const int unsigned MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL = 32768;
		for(unsigned int i = 0; i < MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL; ++i) {
			bool duplicate = colorPicker2.get_next_assign_color(colorPicker2.getUniqueColorID());
			CPPUNIT_ASSERT_EQUAL( (i+1 >= MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL),duplicate );
		}

		BaseColorPickEntity::resetUniqueColors();
		BaseColorPickEntity::setTrackColorUse(false);
	}

	void test_ColorPicking_prime() {

		BaseColorPickEntity::setTrackColorUse(true);
		BaseColorPickEntity::setUsingLoopMethod(false);
		BaseColorPickEntity::resetUniqueColors();

		TestBaseColorPickEntity colorPicker;
		// This is the max color count this algorithm supports
		const int unsigned MAX_SUPPORTED_COLORS_USING_THIS_METHOD = 64005;
		for(unsigned int i = 0; i < MAX_SUPPORTED_COLORS_USING_THIS_METHOD; ++i) {
			bool duplicate = colorPicker.get_next_assign_color(colorPicker.getUniqueColorID());
			CPPUNIT_ASSERT_EQUAL( false,duplicate );
		}

		BaseColorPickEntity::resetUniqueColors();

		TestBaseColorPickEntity colorPicker2;
		// This is a test to prove when the algorithm fails
		const int unsigned MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL = 64006;
		for(unsigned int i = 0; i < MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL; ++i) {
			bool duplicate = colorPicker2.get_next_assign_color(colorPicker2.getUniqueColorID());
			CPPUNIT_ASSERT_EQUAL( (i+1 >= MAX_SUPPORTED_COLORS_USING_THIS_METHOD_FAIL),duplicate );
		}

		BaseColorPickEntity::resetUniqueColors();
		BaseColorPickEntity::setTrackColorUse(false);
	}

};


// Test Suite Registrations
CPPUNIT_TEST_SUITE_REGISTRATION( ModelTest );
//