Adding copyright notices to most files. Also add readme file, and some
[jitcs.git] / tests / test_adt_slice.cpp
blob366a260a81bc9263a607a536c020d69018881e89
1 //===-- tests/test_adt_slice.cpp --------------------------------*- C++ -*-===//
2 // Test to check Slice class.
3 //
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"
9 #include "unittest.h"
11 using namespace jitcs;
13 static void test(UnitTest& t) {
14 size_t data[5] = {0x12345678, 0xdeadbeef, 0x1, ~(size_t)0, 0};
15 Slice<size_t> arr;
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);
27 ++b;
28 t.check("Slice/6", *b == 0xdeadbeef);
29 ++b;
30 ++b;
31 ++b;
32 t.check("Slice/7", b != e);
33 ++b;
34 t.check("Slice/8", b == e);
37 static UnitTestRun _("ADT/Slice", test);