File: ZXAlgorithmsTest.cpp

package info (click to toggle)
zxing-cpp 3.0.2%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,204 kB
  • sloc: ansic: 69,384; cpp: 34,624; php: 2,790; python: 199; makefile: 31; sh: 3
file content (51 lines) | stat: -rw-r--r-- 896 bytes parent folder | download | duplicates (3)
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
/*
* Copyright 2022 Axel Waggershauser
*/
// SPDX-License-Identifier: Apache-2.0

#include "ZXAlgorithms.h"

#include "gtest/gtest.h"

using namespace ZXing;

TEST(ZXAlgorithmsTest, ToDigit)
{
	EXPECT_EQ(ToDigit(0), '0');
	EXPECT_EQ(ToDigit(9), '9');

	EXPECT_THROW(ToDigit(-1), Error);
	EXPECT_THROW(ToDigit(11), Error);
}

TEST(ZXAlgorithmsTest, ToString)
{
	EXPECT_EQ(ToString(0, 1), "0");
	EXPECT_EQ(ToString(0, 2), "00");
	EXPECT_EQ(ToString(1, 3), "001");
	EXPECT_EQ(ToString(99, 2), "99");

	EXPECT_THROW(ToString(-1, 2), Error);
	EXPECT_THROW(ToString(111, 2), Error);
}

TEST(ZXAlgorithmsTest, UpdateMinMax)
{
	int m = 10, M = 0;
	UpdateMinMax(m, M, 5);
	EXPECT_EQ(m, 5);
	EXPECT_EQ(M, 5);

	UpdateMinMax(m, M, 2);
	EXPECT_EQ(m, 2);
	EXPECT_EQ(M, 5);

	m = M = 1;
	UpdateMinMax(m, M, 0);
	EXPECT_EQ(m, 0);
	EXPECT_EQ(M, 1);

	UpdateMinMax(m, M, 2);
	EXPECT_EQ(m, 0);
	EXPECT_EQ(M, 2);
}