1 //===-- tests/test_adt_slice.cpp --------------------------------*- C++ -*-===//
2 // Test to check Slice class.
4 // Copyright (C) 2013-2014 Dirk Steinke.
5 // See copyright and license notice in COPYRIGHT or include/jitcs.h
6 //===----------------------------------------------------------------------===//
8 #include "jitcs_adt_slice.h"
11 using namespace jitcs
;
13 static void test(UnitTest
& t
) {
14 size_t data
[5] = {0x12345678, 0xdeadbeef, 0x1, ~(size_t)0, 0};
16 t
.check("Slice/0", arr
.size() == 0);
17 Slice
<size_t>::iterator b
= arr
.begin(), e
= arr
.end();
18 t
.check("Slice/1", b
== e
);
20 arr
= Slice
<size_t>(data
, 5);
21 t
.check("Slice/2", arr
.size() == 5 && arr
._ptr
== data
);
22 t
.check("Slice/3", arr
.isValidIndex(4) && !arr
.isValidIndex(5));
23 t
.check("Slice/4", arr
[1] == 0xdeadbeef);
25 b
= arr
.begin(), e
= arr
.end();
26 t
.check("Slice/5", b
!= e
);
28 t
.check("Slice/6", *b
== 0xdeadbeef);
32 t
.check("Slice/7", b
!= e
);
34 t
.check("Slice/8", b
== e
);
37 static UnitTestRun
_("ADT/Slice", test
);