Echo Writes Code

test_random.cpp

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
#include "crucible/core.hpp"
#include "crucible/test.hpp"

#include <cstdint>
#include <limits>

namespace test_random
{
	CRUCIBLE_TEST_SCENARIO(read_random_integers)
	{
		auto const u8 {
			[]() {
				auto const result { crucible::read_random_integer<std::uint8_t>() };
				CRUCIBLE_ASSERT_SUCCESS(result);
				return result.success();
			}()
		};

		CRUCIBLE_ASSERT_GE(u8, 0);
		CRUCIBLE_ASSERT_LE(u8, std::numeric_limits<std::uint8_t>::max());

		auto const u16 {
			[]() {
				auto const result { crucible::read_random_integer<std::uint16_t>() };
				CRUCIBLE_ASSERT_SUCCESS(result);
				return result.success();
			}()
		};

		CRUCIBLE_ASSERT_GE(u16, 0);
		CRUCIBLE_ASSERT_LE(u16, std::numeric_limits<std::uint16_t>::max());

		auto const u32 {
			[]() {
				auto const result { crucible::read_random_integer<std::uint32_t>() };
				CRUCIBLE_ASSERT_SUCCESS(result);
				return result.success();
			}()
		};

		CRUCIBLE_ASSERT_GE(u32, 0);
		CRUCIBLE_ASSERT_LE(u32, std::numeric_limits<std::uint32_t>::max());

		auto const u64 {
			[]() {
				auto const result { crucible::read_random_integer<std::uint64_t>() };
				CRUCIBLE_ASSERT_SUCCESS(result);
				return result.success();
			}()
		};

		CRUCIBLE_ASSERT_GE(u64, 0);
		CRUCIBLE_ASSERT_LE(u64, std::numeric_limits<std::uint64_t>::max());
	}
}

CRUCIBLE_TEST_MAIN