• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef LIBCPP_TEST_BITSET_TEST_CASES_H
9 #define LIBCPP_TEST_BITSET_TEST_CASES_H
10 
11 #include <bitset>
12 #include <string>
13 #include <vector>
14 
15 template <int N>
16 std::vector<std::bitset<N> > get_test_cases();
17 
18 template <>
19 inline std::vector<std::bitset<0> > get_test_cases<0>() {
20     std::vector<std::bitset<0> > cases;
21     cases.push_back(std::bitset<0>());
22     return cases;
23 }
24 
25 template <>
26 inline std::vector<std::bitset<1> > get_test_cases<1>() {
27     std::vector<std::bitset<1> > cases;
28     cases.push_back(std::bitset<1>("0"));
29     cases.push_back(std::bitset<1>("1"));
30     return cases;
31 }
32 
33 template <>
34 inline std::vector<std::bitset<2> > get_test_cases<2>() {
35     std::vector<std::bitset<2> > cases;
36     cases.push_back(std::bitset<2>("00"));
37     cases.push_back(std::bitset<2>("01"));
38     cases.push_back(std::bitset<2>("10"));
39     cases.push_back(std::bitset<2>("11"));
40     return cases;
41 }
42 
43 template <>
44 inline std::vector<std::bitset<31> > get_test_cases<31>() {
45     std::vector<std::bitset<31> > cases;
46     cases.push_back(std::bitset<31>("0000000000000000000000000000000"));
47     cases.push_back(std::bitset<31>("0000000000000000000000000000001"));
48     cases.push_back(std::bitset<31>("1000000000000000000000000000000"));
49     cases.push_back(std::bitset<31>("1000000000000000000000000000001"));
50     cases.push_back(std::bitset<31>("1000000000000000000001000000001"));
51     cases.push_back(std::bitset<31>("0000000000000000111111111111111"));
52     cases.push_back(std::bitset<31>("1000000000000000111111111111111"));
53     cases.push_back(std::bitset<31>("1111111111111111000000000000000"));
54     cases.push_back(std::bitset<31>("1111111111111111000000000000001"));
55     cases.push_back(std::bitset<31>("1010101010101010101010101010101"));
56     cases.push_back(std::bitset<31>("0101010101010101010101010101010"));
57     cases.push_back(std::bitset<31>("1111111111111111111111111111111"));
58     return cases;
59 }
60 
61 template <>
62 inline std::vector<std::bitset<32> > get_test_cases<32>() {
63     std::vector<std::bitset<32> > cases;
64     cases.push_back(std::bitset<32>("00000000000000000000000000000000"));
65     cases.push_back(std::bitset<32>("00000000000000000000000000000001"));
66     cases.push_back(std::bitset<32>("10000000000000000000000000000000"));
67     cases.push_back(std::bitset<32>("10000000000000000000000000000001"));
68     cases.push_back(std::bitset<32>("10000000000000000000111000000001"));
69     cases.push_back(std::bitset<32>("00000000000000001111111111111111"));
70     cases.push_back(std::bitset<32>("10000000000000001111111111111111"));
71     cases.push_back(std::bitset<32>("11111111111111110000000000000000"));
72     cases.push_back(std::bitset<32>("11111111111111110000000000000001"));
73     cases.push_back(std::bitset<32>("10101010101010101010101010101010"));
74     cases.push_back(std::bitset<32>("01010101010101010101010101010101"));
75     cases.push_back(std::bitset<32>("11111111111111111111111111111111"));
76     return cases;
77 }
78 
79 template <>
80 inline std::vector<std::bitset<33> > get_test_cases<33>() {
81     std::vector<std::bitset<33> > cases;
82     cases.push_back(std::bitset<33>("000000000000000000000000000000000"));
83     cases.push_back(std::bitset<33>("000000000000000000000000000000001"));
84     cases.push_back(std::bitset<33>("100000000000000000000000000000000"));
85     cases.push_back(std::bitset<33>("100000000000000000000000000000001"));
86     cases.push_back(std::bitset<33>("100000000000000000001110000000001"));
87     cases.push_back(std::bitset<33>("000000000000000011111111111111111"));
88     cases.push_back(std::bitset<33>("100000000000000011111111111111111"));
89     cases.push_back(std::bitset<33>("111111111111111100000000000000000"));
90     cases.push_back(std::bitset<33>("111111111111111100000000000000001"));
91     cases.push_back(std::bitset<33>("101010101010101010101010101010101"));
92     cases.push_back(std::bitset<33>("010101010101010101010101010101010"));
93     cases.push_back(std::bitset<33>("111111111111111111111111111111111"));
94     return cases;
95 }
96 
97 template <>
98 inline std::vector<std::bitset<63> > get_test_cases<63>() {
99     std::vector<std::bitset<63> > cases;
100     cases.push_back(std::bitset<63>("000000000000000000000000000000000000000000000000000000000000000"));
101     cases.push_back(std::bitset<63>("000000000000000000000000000000000000000000000000000000000000001"));
102     cases.push_back(std::bitset<63>("100000000000000000000000000000000000000000000000000000000000000"));
103     cases.push_back(std::bitset<63>("100000000000000000000000000000000000000000000000000000000000001"));
104     cases.push_back(std::bitset<63>("100000000000000000000000001111100000000000000000000000000000001"));
105     cases.push_back(std::bitset<63>("000000000000000000000000000000001111111111111111111111111111111"));
106     cases.push_back(std::bitset<63>("100000000000000000000000000000001111111111111111111111111111111"));
107     cases.push_back(std::bitset<63>("111111111111111111111111111111110000000000000000000000000000000"));
108     cases.push_back(std::bitset<63>("111111111111111111111111111111110000000000000000000000000000001"));
109     cases.push_back(std::bitset<63>("101010101010101010101010101010101010101010101010101010101010101"));
110     cases.push_back(std::bitset<63>("010101010101010101010101010101010101010101010101010101010101010"));
111     cases.push_back(std::bitset<63>("111111111111111111111111111111111111111111111111111111111111111"));
112     return cases;
113 }
114 
115 template <>
116 inline std::vector<std::bitset<64> > get_test_cases<64>() {
117     std::vector<std::bitset<64> > cases;
118     cases.push_back(std::bitset<64>("0000000000000000000000000000000000000000000000000000000000000000"));
119     cases.push_back(std::bitset<64>("0000000000000000000000000000000000000000000000000000000000000001"));
120     cases.push_back(std::bitset<64>("1000000000000000000000000000000000000000000000000000000000000000"));
121     cases.push_back(std::bitset<64>("1000000000000000000000000000000000000000000000000000000000000001"));
122     cases.push_back(std::bitset<64>("1000000000000000000000000011111000000000000000000000000000000001"));
123     cases.push_back(std::bitset<64>("0000000000000000000000000000000011111111111111111111111111111111"));
124     cases.push_back(std::bitset<64>("1000000000000000000000000000000011111111111111111111111111111111"));
125     cases.push_back(std::bitset<64>("1111111111111111111111111111111100000000000000000000000000000000"));
126     cases.push_back(std::bitset<64>("1111111111111111111111111111111100000000000000000000000000000001"));
127     cases.push_back(std::bitset<64>("1010101010101010101010101010101010101010101010101010101010101010"));
128     cases.push_back(std::bitset<64>("0101010101010101010101010101010101010101010101010101010101010101"));
129     cases.push_back(std::bitset<64>("1111111111111111111111111111111111111111111111111111111111111111"));
130     return cases;
131 }
132 
133 template <>
134 inline std::vector<std::bitset<65> > get_test_cases<65>() {
135     std::vector<std::bitset<65> > cases;
136     cases.push_back(std::bitset<65>("00000000000000000000000000000000000000000000000000000000000000000"));
137     cases.push_back(std::bitset<65>("00000000000000000000000000000000000000000000000000000000000000001"));
138     cases.push_back(std::bitset<65>("10000000000000000000000000000000000000000000000000000000000000000"));
139     cases.push_back(std::bitset<65>("10000000000000000000000000000000000000000000000000000000000000001"));
140     cases.push_back(std::bitset<65>("10000000000000000000000000011111000000000000000000000000000000001"));
141     cases.push_back(std::bitset<65>("00000000000000000000000000000000011111111111111111111111111111111"));
142     cases.push_back(std::bitset<65>("10000000000000000000000000000000011111111111111111111111111111111"));
143     cases.push_back(std::bitset<65>("11111111111111111111111111111111000000000000000000000000000000000"));
144     cases.push_back(std::bitset<65>("11111111111111111111111111111111000000000000000000000000000000001"));
145     cases.push_back(std::bitset<65>("10101010101010101010101010101010101010101010101010101010101010101"));
146     cases.push_back(std::bitset<65>("01010101010101010101010101010101010101010101010101010101010101010"));
147     cases.push_back(std::bitset<65>("11111111111111111111111111111111111111111111111111111111111111111"));
148     return cases;
149 }
150 
str_repeat(std::string s,unsigned int n)151 inline std::string str_repeat(std::string s, unsigned int n) {
152     std::string res = s;
153     for (; n != 0; --n)
154         res += s;
155     return res;
156 }
157 
158 template <>
159 inline std::vector<std::bitset<1000> > get_test_cases<1000>() {
160     std::vector<std::bitset<1000> > cases;
161     cases.push_back(std::bitset<1000>(std::string(1000, '0')));
162     cases.push_back(std::bitset<1000>(std::string(999, '0') + std::string(1, '1')));
163     cases.push_back(std::bitset<1000>(std::string(1, '1') + std::string(999, '0')));
164     cases.push_back(std::bitset<1000>(std::string(1, '1') + std::string(998, '0') + std::string(1, '1')));
165     cases.push_back(std::bitset<1000>(std::string(1, '1') + std::string(400, '0') + std::string(99, '1') + std::string(499, '0') + std::string(1, '1')));
166     cases.push_back(std::bitset<1000>(std::string(500, '0') + std::string(500, '1')));
167     cases.push_back(std::bitset<1000>(std::string(1, '1') + std::string(499, '0') + std::string(500, '1')));
168     cases.push_back(std::bitset<1000>(std::string(500, '1') + std::string(500, '0')));
169     cases.push_back(std::bitset<1000>(std::string(500, '1') + std::string(499, '0') + std::string(1, '1')));
170     cases.push_back(std::bitset<1000>(str_repeat("10", 500)));
171     cases.push_back(std::bitset<1000>(str_repeat("01", 500)));
172     cases.push_back(std::bitset<1000>(std::string(1000, '1')));
173 
174     return cases;
175 }
176 
177 #endif // !LIBCPP_TEST_BITSET_TEST_CASES_H
178