ArmNN
 20.02
PrototxtConversionsTest.cpp File Reference
#include <PrototxtConversions.hpp>
#include "armnn/Tensor.hpp"
#include <boost/test/unit_test.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (ConvertInt32ToOctalStringTest)
 
 BOOST_AUTO_TEST_CASE (ConvertTensorShapeToStringTest)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/2]

BOOST_AUTO_TEST_CASE ( ConvertInt32ToOctalStringTest  )

Definition at line 13 of file PrototxtConversionsTest.cpp.

References armnnUtils::ConvertInt32ToOctalString().

14 {
16 
17  std::string octalString = ConvertInt32ToOctalString(1);
18  BOOST_ASSERT(octalString.compare("\\\\001\\\\000\\\\000\\\\000"));
19 
20  octalString = ConvertInt32ToOctalString(256);
21  BOOST_ASSERT(octalString.compare("\\\\000\\\\100\\\\000\\\\000"));
22 
23  octalString = ConvertInt32ToOctalString(65536);
24  BOOST_ASSERT(octalString.compare("\\\\000\\\\000\\\\100\\\\000"));
25 
26  octalString = ConvertInt32ToOctalString(16777216);
27  BOOST_ASSERT(octalString.compare("\\\\000\\\\000\\\\000\\\\100"));
28 
29  octalString = ConvertInt32ToOctalString(-1);
30  BOOST_ASSERT(octalString.compare("\\\\377\\\\377\\\\377\\\\377"));
31 
32  octalString = ConvertInt32ToOctalString(-256);
33  BOOST_ASSERT(octalString.compare("\\\\000\\\\377\\\\377\\\\377"));
34 
35  octalString = ConvertInt32ToOctalString(-65536);
36  BOOST_ASSERT(octalString.compare("\\\\000\\\\000\\\\377\\\\377"));
37 
38  octalString = ConvertInt32ToOctalString(-16777216);
39  BOOST_ASSERT(octalString.compare("\\\\000\\\\000\\\\000\\\\377"));
40 }
std::string ConvertInt32ToOctalString(int value)
Converts an int value into the Prototxt octal representation.

◆ BOOST_AUTO_TEST_CASE() [2/2]

BOOST_AUTO_TEST_CASE ( ConvertTensorShapeToStringTest  )

Definition at line 42 of file PrototxtConversionsTest.cpp.

References BOOST_AUTO_TEST_SUITE_END(), and armnnUtils::ConvertTensorShapeToString().

43 {
45  using armnn::TensorShape;
46 
47  auto createAndConvert = [](std::initializer_list<unsigned int> dims) -> std::string
48  {
49  auto shape = TensorShape{dims};
50  return ConvertTensorShapeToString(shape);
51  };
52 
53  auto output_string = createAndConvert({5});
54  BOOST_ASSERT(output_string.compare(
55  "dim {\n"
56  "size: 5\n"
57  "}"));
58 
59  output_string = createAndConvert({4, 5});
60  BOOST_ASSERT(output_string.compare(
61  "dim {\n"
62  "size: 4\n"
63  "}\n"
64  "dim {\n"
65  "size: 5\n"
66  "}"
67  ));
68 
69  output_string = createAndConvert({3, 4, 5});
70  BOOST_ASSERT(output_string.compare(
71  "dim {\n"
72  "size: 3\n"
73  "}\n"
74  "dim {\n"
75  "size: 4\n"
76  "}\n"
77  "dim {\n"
78  "size: 5\n"
79  "}"
80  ));
81 
82  output_string = createAndConvert({2, 3, 4, 5});
83  BOOST_ASSERT(output_string.compare(
84  "dim {\n"
85  "size: 2\n"
86  "}\n"
87  "dim {\n"
88  "size: 3\n"
89  "}\n"
90  "dim {\n"
91  "size: 4\n"
92  "}\n"
93  "dim {\n"
94  "size: 5\n"
95  "}"
96  ));
97 
98  output_string = createAndConvert({1, 2, 3, 4, 5});
99  BOOST_ASSERT(output_string.compare(
100  "dim {\n"
101  "size: 1\n"
102  "}\n"
103  "dim {\n"
104  "size: 2\n"
105  "}\n"
106  "dim {\n"
107  "size: 3\n"
108  "}\n"
109  "dim {\n"
110  "size: 4\n"
111  "}\n"
112  "dim {\n"
113  "size: 5\n"
114  "}"
115  ));
116 
117  output_string = createAndConvert({0xffffffff, 0xffffffff});
118  BOOST_ASSERT(output_string.compare(
119  "dim {\n"
120  "size: 4294967295\n"
121  "}\n"
122  "dim {\n"
123  "size: 4294967295\n"
124  "}"
125  ));
126 
127  output_string = createAndConvert({1, 0});
128  BOOST_ASSERT(output_string.compare(
129  "dim {\n"
130  "size: 1\n"
131  "}\n"
132  "dim {\n"
133  "size: 0\n"
134  "}"
135  ));
136 }
std::string ConvertTensorShapeToString(const armnn::TensorShape &shape)
Converts an TensorShape into Prototxt representation.