blob: d19b0cfdb60335c88a03fc202b93e1b5f1b0c5cb [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +00007
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/utils/SkBitSet.h"
9#include "tests/Test.h"
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000010
Hal Canary9e41c212018-09-03 12:00:23 -040011#include <vector>
12
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +000013DEF_TEST(BitSet, reporter) {
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000014 SkBitSet set0(65536);
Ben Wagnere2a94432020-05-04 17:42:34 -040015 REPORTER_ASSERT(reporter, set0.size() == 65536);
16 REPORTER_ASSERT(reporter, set0.test(0) == false);
17 REPORTER_ASSERT(reporter, set0.test(32767) == false);
18 REPORTER_ASSERT(reporter, set0.test(65535) == false);
19 REPORTER_ASSERT(reporter, !set0.findFirst());
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000020
halcanarye2348cc2016-08-19 16:23:23 -070021 set0.set(22);
Ben Wagnere2a94432020-05-04 17:42:34 -040022 REPORTER_ASSERT(reporter, set0.test(22) == true);
23 REPORTER_ASSERT(reporter, set0.findFirst());
24 REPORTER_ASSERT(reporter, *set0.findFirst() == 22);
halcanarye2348cc2016-08-19 16:23:23 -070025 set0.set(24);
Ben Wagnere2a94432020-05-04 17:42:34 -040026 REPORTER_ASSERT(reporter, set0.test(24) == true);
27 REPORTER_ASSERT(reporter, *set0.findFirst() == 22);
halcanarye2348cc2016-08-19 16:23:23 -070028 set0.set(35); // on a different DWORD
Ben Wagnere2a94432020-05-04 17:42:34 -040029 REPORTER_ASSERT(reporter, set0.test(35) == true);
30 REPORTER_ASSERT(reporter, *set0.findFirst() == 22);
31 REPORTER_ASSERT(reporter, set0.test(24) == true);
32 REPORTER_ASSERT(reporter, set0.test(35) == true);
33 set0.set(21);
34 REPORTER_ASSERT(reporter, set0.test(21) == true);
35 REPORTER_ASSERT(reporter, *set0.findFirst() == 21);
36 set0.reset(21);
37 REPORTER_ASSERT(reporter, set0.test(21) == false);
38 REPORTER_ASSERT(reporter, *set0.findFirst() == 22);
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000039
Hal Canary9e41c212018-09-03 12:00:23 -040040 std::vector<unsigned int> data;
Ben Wagnere2a94432020-05-04 17:42:34 -040041 set0.forEachSetIndex([&data](unsigned v) { data.push_back(v); });
Hal Canary52514d52018-10-19 10:08:42 -040042
Hal Canary9e41c212018-09-03 12:00:23 -040043 REPORTER_ASSERT(reporter, data.size() == 3);
halcanarye2348cc2016-08-19 16:23:23 -070044 REPORTER_ASSERT(reporter, data[0] == 22);
45 REPORTER_ASSERT(reporter, data[1] == 24);
46 REPORTER_ASSERT(reporter, data[2] == 35);
vandebo@chromium.org17e66e22011-07-27 20:59:55 +000047
halcanarye2348cc2016-08-19 16:23:23 -070048 SkBitSet set1(65536);
49 set1.set(12345);
Ben Wagnere2a94432020-05-04 17:42:34 -040050 REPORTER_ASSERT(reporter, set0.test(12345) == false);
51 REPORTER_ASSERT(reporter, set1.test(12345) == true);
52 REPORTER_ASSERT(reporter, set1.test(22) == false);
53 REPORTER_ASSERT(reporter, set0.test(35) == true);
vandebo@chromium.orgd3a8c942011-07-02 01:26:37 +000054}