File: common_check.cpp

package info (click to toggle)
teg 0.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,036 kB
  • sloc: cpp: 16,819; xml: 1,313; makefile: 268; sh: 195; ansic: 112
file content (91 lines) | stat: -rw-r--r-- 2,494 bytes parent folder | download
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// SPDX-License-Identifier: GPL-2.0-or-later

#include "common.h"

#include <cstring>

#include <gtest/gtest.h>

TEST(Common, cards_for_this_exchange)
{
	EXPECT_EQ(0, cards_for_this_exchange(0));
	EXPECT_EQ(4, cards_for_this_exchange(1));
	EXPECT_EQ(7, cards_for_this_exchange(2));
	EXPECT_EQ(10, cards_for_this_exchange(3));
	EXPECT_EQ(15, cards_for_this_exchange(4));
	EXPECT_EQ(20, cards_for_this_exchange(5));
	EXPECT_EQ(45, cards_for_this_exchange(10));
	EXPECT_EQ(495, cards_for_this_exchange(100));
}

TEST(Common, strip_invalid)
{
	char string[] = "a=b:c\\d,e:f/g%h\"i";
	strip_invalid(string);
	EXPECT_STREQ("a.b.c.d.e.f.g.h\"i", string);
}

TEST(Common, strip_invalid_msg)
{
	char string[] = "a=b:c\\d,e:f/g%h\"i";
	strip_invalid_msg(string);
	EXPECT_STREQ("a=b:c\\d,e:f/g%h\'i", string);
}

TEST(Common, my_atoi)
{
	EXPECT_EQ(-1, my_atoi(nullptr));
	EXPECT_EQ(-50, my_atoi("-50"));
	EXPECT_EQ(-1, my_atoi("-1"));
	EXPECT_EQ(0, my_atoi("0"));
	EXPECT_EQ(1, my_atoi("1"));
	EXPECT_EQ(23, my_atoi("23"));
}

TEST(Common, string_copy)
{
	char dest[5];

	std::memset(dest, '#', sizeof(dest));
	string_copy(dest+2, sizeof(dest)-2, "asdfg");
	EXPECT_STREQ("##as", dest);

	std::memset(dest, '#', sizeof(dest));
	string_copy(dest, sizeof(dest), "abc");
	EXPECT_STREQ("abc", dest);

	std::memset(dest, '#', sizeof(dest));
	string_copy(dest, sizeof(dest), "abcdefg");
	EXPECT_STREQ("abcd", dest);

	std::memset(dest, '#', sizeof(dest));
	string_copy(dest, 1, "abcdefg");
	EXPECT_STREQ("", dest);
}

TEST(Common, replace_continents)
{
	ContinentNames const replacements{
		"Foo",
		"Bar",
		"Baz",
		"BigBigBigContinentName",
		"!'§$%&/()=?",
		"No. 6"
	};
	EXPECT_EQ("", replace_continents("", replacements));
	EXPECT_EQ("Foo", replace_continents("&0", replacements));
	EXPECT_EQ("Bar", replace_continents("&1", replacements));
	EXPECT_EQ("Baz", replace_continents("&2", replacements));
	EXPECT_EQ("BigBigBigContinentName", replace_continents("&3", replacements));
	EXPECT_EQ("!'§$%&/()=?", replace_continents("&4", replacements));
	EXPECT_EQ("No. 6", replace_continents("&5", replacements));
	EXPECT_EQ("", replace_continents("&6", replacements));

	EXPECT_EQ("x Bar y", replace_continents("x &1 y", replacements));
	EXPECT_EQ("Conquer BigBigBigContinentName, !'§$%&/()=?, Bar, Baz, Foo "
	          "with the focus on BigBigBigContinentName -- No. 6",
	          replace_continents(
	              "Conquer &3, &4, &1, &2, &0 with the focus on &3 -- &5",
	              replacements));
}