monotone

monotone Mtn Source Tree

Root/string_queue.cc

1// unit tests for string_queue
2
3
4#include "base.hh"
5#include "string_queue.hh"
6
7#ifdef BUILD_UNIT_TESTS
8
9#include "unit_tests.hh"
10
11using std::logic_error;
12
13UNIT_TEST(string_queue, string_queue)
14{
15 string_queue sq1;
16
17 UNIT_TEST_CHECKPOINT( "append" );
18
19 sq1.append("123");
20 sq1.append("45z", 2); // 'z' shall be ignored
21 sq1.append('6');
22
23 UNIT_TEST_CHECK( sq1.size() == 6 );
24
25 UNIT_TEST_CHECKPOINT( "retrieve" );
26
27 UNIT_TEST_CHECK( sq1.substr(0, 6) == "123456" );
28 UNIT_TEST_CHECK( sq1.substr(3, 2) == "45" );
29
30 UNIT_TEST_CHECK( sq1[5] == '6' );
31 UNIT_TEST_CHECK( sq1[0] == '1' );
32
33 UNIT_TEST_CHECK( *(sq1.front_pointer(6)) == '1');
34
35 UNIT_TEST_CHECK( sq1.size() == 6);
36
37 UNIT_TEST_CHECKPOINT( "failures" );
38
39 // check a few things will fail
40 UNIT_TEST_CHECK_THROW( sq1.substr(3, 4), logic_error );
41 UNIT_TEST_CHECK_THROW( sq1.front_pointer(7), logic_error );
42
43 // modification
44 UNIT_TEST_CHECKPOINT( "modification" );
45
46 sq1[5] = 'r';
47 UNIT_TEST_CHECK_THROW( sq1[6], logic_error );
48
49 UNIT_TEST_CHECK( sq1[5] == 'r' );
50 UNIT_TEST_CHECK( sq1.substr(3, 3) == "45r" );
51
52 // empty it out
53 UNIT_TEST_CHECKPOINT( "emptying" );
54
55 UNIT_TEST_CHECK_THROW( sq1.pop_front( 7 ), logic_error );
56 sq1.pop_front(1);
57 UNIT_TEST_CHECK( sq1.size() == 5 );
58 UNIT_TEST_CHECK(sq1[0] == '2');
59
60 UNIT_TEST_CHECK(sq1[4] == 'r');
61 UNIT_TEST_CHECK_THROW( sq1[5], logic_error );
62 UNIT_TEST_CHECK_THROW( sq1.pop_front( 6 ), logic_error );
63 sq1.pop_front(5);
64 UNIT_TEST_CHECK_THROW( sq1.pop_front( 1 ), logic_error );
65
66 // it's empty again
67 UNIT_TEST_CHECK( sq1.size() == 0 );
68}
69
70#endif // BUILD_UNIT_TESTS
71
72// Local Variables:
73// mode: C++
74// fill-column: 76
75// c-file-style: "gnu"
76// indent-tabs-mode: nil
77// End:
78// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status