forked from Harrm/scale-codec
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathscale_array_test.cpp
More file actions
45 lines (39 loc) · 1.04 KB
/
Copy pathscale_array_test.cpp
File metadata and controls
45 lines (39 loc) · 1.04 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
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/
#include <gtest/gtest.h>
#include <qtils/test/outcome.hpp>
#include <scale/scale.hpp>
using scale::impl::memory::decode;
using scale::impl::memory::encode;
/**
* @given collection of N of type uint8_t
* @when encode array and decode back
* @then given equal array
*/
template <size_t N, typename Array = std::array<uint8_t, N>>
void testArray() {
for (auto value : {0b0000'0000,
0b0011'0011,
0b0101'0101,
0b1010'1010,
0b1100'1100,
0b1111'1111}) {
Array testee{};
std::ranges::fill(testee, value);
ASSERT_OUTCOME_SUCCESS(data, encode(testee));
ASSERT_OUTCOME_SUCCESS(result, decode<Array>(data));
EXPECT_EQ(testee, result);
}
}
/// Doing test of encode/decode different size arrays
TEST(Scale, encodeArray) {
testArray<0>();
testArray<127>();
testArray<128>();
testArray<255>();
testArray<256>();
testArray<999>();
}