/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-05-29 10:32:28 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20220529103228-unjhkil8jtaxnzk1
Added a simple stack type.

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
  Test.add_func (UTIL_TEST_STACK_PREFIX + "push_pop", () => {
 
20
    var stk = new Stack<int> ();
 
21
    stk.push (1337);
 
22
    if (stk.is_empty ()) {
 
23
      Test.fail ();
 
24
      Test.message ("Stack reports that it's empty, " +
 
25
                    "when it shouln't be.");
 
26
    }
 
27
 
 
28
    stk.pop ();
 
29
     
 
30
    if (stk.is_empty () == false) {
 
31
      Test.fail ();
 
32
      Test.message ("Stack reports that it's not empty," +
 
33
                    " when it's only value has been poped.");
 
34
    }
 
35
    
 
36
  });
 
37
 
 
38
 
 
39
  Test.add_func (UTIL_TEST_STACK_PREFIX + "value", () => {
 
40
    var stk = new Stack<int> ();
 
41
    
 
42
    stk.push (1337);
 
43
 
 
44
    if (stk.peek () != 1337) {
 
45
      Test.fail ();
 
46
      Test.message ("Peeked value did not match exepcted value.");
 
47
    }
 
48
 
 
49
    if (stk.pop () != 1337) {
 
50
      Test.fail ();
 
51
      Test.message ("Poped value does not match expected value.");
 
52
    }
 
53
    
 
54
    foreach (var i in new Range (0, 10000) ) {
 
55
      stk.push (i);
 
56
    }
 
57
    
 
58
    foreach (var i in new Range (10000, 0)) {
 
59
      int got_val = stk.pop ();
 
60
      if (i != got_val) {
 
61
         Test.fail ();
 
62
         Test.message ("Wrong value: Expeted %i, get %i.",
 
63
                       i, got_val);
 
64
      }
 
65
    }
 
66
 
 
67
  });
 
68
}