summaryrefslogtreecommitdiff
path: root/modules/codec-unit/tests/codec-unit.cpp
blob: 39e590dce94401c3af6cbffc98ce3ea9671e34fb (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
#include <forstio/test/suite.hpp>

#include <forstio/codec/schema.hpp>

#include "../c++/unit.hpp"

namespace {
namespace sch {
using namespace saw::schema;

struct FanMeterEle {};

using FanMeter = Unit<
	Int64,
	UnitElement<FanMeterEle,1>
>;

using FanSquareMeter = Unit<
	Int64,
	UnitElement<FanMeterEle,2>
>;
}


SAW_TEST("Codec Unit/Addition"){
	using namespace saw;

	data<sch::FanMeter> a{{5}}, b{{4}};

	auto c = a + b;

	SAW_EXPECT(c == data<sch::FanMeter>{9u}, "Expected result 9");
}

SAW_TEST("Codec Unit/Subtraction"){
	using namespace saw;

	data<sch::FanMeter> a{{5}}, b{{4}};

	auto c = a - b;

	SAW_EXPECT(c == data<sch::FanMeter>{1u}, "Expected result 1");
}

SAW_TEST("Codec Unit/Multiplication"){
	using namespace saw;

	data<sch::FanMeter> a{{5}}, b{{4}};

	auto c = a * b;

	SAW_EXPECT(c == data<sch::FanSquareMeter>{20u}, "Expected result 20");
}

SAW_TEST("Codec Unit/Division"){
	using namespace saw;

	data<sch::FanMeter> a{{20}}, b{{4}};

	auto c = a / b;

	SAW_EXPECT(c == data<sch::Scalar<sch::Int64>>{5u}, "Expected result 5");
}
}