-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest.cpp
More file actions
109 lines (76 loc) · 3.02 KB
/
test.cpp
File metadata and controls
109 lines (76 loc) · 3.02 KB
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
109
#include "tinytest.h"
//factory
#include "ConverterFactory.hpp"
//basic class
#include "UnitConverter.hpp"
//derived classes
#include "DollarToEuroConverter.hpp"
#include "CelsiusToFahrenheitConverter.hpp"
#include "FahrenheitToCelsiusConverter.hpp"
#include "YenToEuroConverter.hpp"
#include "GoldToEuroConverter.hpp"
ConverterFactory* ConverterFactory::s_instance = nullptr;
int test_DollarToEuro()
{
std::string converter_string = "DollarToEuro";
//creating the factory
auto factory = ConverterFactory::instance();
//registering converters
factory->add_object_to_registry(converter_string, std::make_shared<DollarToEuroConverter>());
auto converter = factory->create(converter_string);
TINYTEST_EQUAL_EPSILON(converter->convert(0.0), 0.0);
TINYTEST_EQUAL_EPSILON(converter->convert(11.363636), 10.0);
TINYTEST_EQUAL_EPSILON(converter->convert(22.9318181), 20.18);
return 1; // Always return a value different than 0 at test end.
}
int test_CelsiusToFahrenheit()
{
std::string converter_string = "CelsiusToFahrenheit";
//creating the factory
auto factory = ConverterFactory::instance();
//registering converters
factory->add_object_to_registry(converter_string, std::make_shared<CelsiusToFahrenheitConverter>());
auto converter = factory->create(converter_string);
TINYTEST_EQUAL_EPSILON(converter->convert(0.0), 32.0);
TINYTEST_EQUAL_EPSILON(converter->convert(32.0), 89.6);
TINYTEST_EQUAL_EPSILON(converter->convert(-10), 14.0);
return 1; // Always return a value different than 0 at test end.
}
int test_FahrenheitToCelsius()
{
std::string converter_string = "FahrenheitToCelsius";
//creating the factory
auto factory = ConverterFactory::instance();
//registering converters
factory->add_object_to_registry(converter_string, std::make_shared<CelsiusToFahrenheitConverter>());
auto converter = factory->create(converter_string);
TINYTEST_EQUAL_EPSILON(converter->convert(32.0), 0.0);
TINYTEST_EQUAL_EPSILON(converter->convert(89.6), 32.0);
TINYTEST_EQUAL_EPSILON(converter->convert(14.0), -10);
return 1; // Always return a value different than 0 at test end.
}
/*
GoldToEuro has been skipped because of finanical crisis (or vague values)
*/
int test_YenToEuro()
{
std::string converter_string = "YenToEuro";
//creating the factory
auto factory = ConverterFactory::instance();
//registering converters
factory->add_object_to_registry(converter_string, std::make_shared<CelsiusToFahrenheitConverter>());
auto converter = factory->create(converter_string);
TINYTEST_EQUAL_EPSILON(converter->convert(32.0), 0.0);
TINYTEST_EQUAL_EPSILON(converter->convert(89.6), 32.0);
TINYTEST_EQUAL_EPSILON(converter->convert(14.0), -10);
return 1; // Always return a value different than 0 at test end.
}
TINYTEST_START_SUITE(ConverterSuite);
// Currency Tests
TINYTEST_ADD_TEST(test_DollarToEuro);
//TINYTEST_ADD_TEST(testEuroToDollar);
//TINYTEST_ADD_TEST(testEuroToDanishKrone);
//TINYTEST_ADD_TEST(testCentsToInches);
//TINYTEST_ADD_TEST(testKilometersToMiles);
TINYTEST_END_SUITE();
TINYTEST_MAIN_SINGLE_SUITE(ConverterSuite);