/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk

« back to all changes in this revision

Viewing changes to tests/utils/stack.vala

  • Committer: Gustav Hartvigsson
  • Date: 2022-06-01 12:14:52 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20220601121452-ntu94w67q3dhhfeq
More work torwards inperementing the parser.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using Utils;
 
2
using GLib;
 
3
 
 
4
void stack_test () {
 
5
  Test.add_func (UTIL_TEST_STACK_PREFIX + "new", () => {
 
6
    var stk = new Stack<int> ();
 
7
    if (stk == null) {
 
8
      Test.fail ();
 
9
      Test.message ("Could not create stack");
 
10
    }
 
11
 
 
12
    if (stk.is_empty () == false) {
 
13
      Test.fail ();
 
14
      Test.message ("The newly created Stack" +
 
15
                    " has the reports it's not empty.");
 
16
    }
 
17
    
 
18
  });
 
19
 
 
20
  Test.add_func (UTIL_TEST_STACK_PREFIX + "push_pop", () => {
 
21
    var stk = new Stack<int> ();
 
22
    stk.push (1337);
 
23
    if (stk.is_empty ()) {
 
24
      Test.fail ();
 
25
      Test.message ("Stack reports that it's empty, " +
 
26
                    "when it shouln't be.");
 
27
    }
 
28
 
 
29
    stk.pop ();
 
30
     
 
31
    if (stk.is_empty () == false) {
 
32
      Test.fail ();
 
33
      Test.message ("Stack reports that it's not empty," +
 
34
                    " when it's only value has been poped.");
 
35
    }
 
36
    
 
37
  });
 
38
 
 
39
 
 
40
  Test.add_func (UTIL_TEST_STACK_PREFIX + "value", () => {
 
41
    var stk = new Stack<int> ();
 
42
    
 
43
    stk.push (1337);
 
44
 
 
45
    if (stk.peek () != 1337) {
 
46
      Test.fail ();
 
47
      Test.message ("Peeked value did not match exepcted value.");
 
48
    }
 
49
 
 
50
    if (stk.pop () != 1337) {
 
51
      Test.fail ();
 
52
      Test.message ("Poped value does not match expected value.");
 
53
    }
 
54
    
 
55
    foreach (var i in new Range (0, 10000) ) {
 
56
      stk.push (i);
 
57
    }
 
58
    
 
59
    foreach (var i in new Range (10000, 0)) {
 
60
      int got_val = stk.pop ();
 
61
      if (i != got_val) {
 
62
         Test.fail ();
 
63
         Test.message ("Wrong value: Expeted %i, get %i.",
 
64
                       i, got_val);
 
65
      }
 
66
    }
 
67
 
 
68
  });
 
69
}