/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/libvee/stack.vala

  • Committer: Gustav Hartvigsson
  • Date: 2020-06-07 18:48:24 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20200607184824-jf14f7a1b1di2i2q
* Initial code - far from done

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
using Vee;
2
 
using GLib;
3
 
 
4
 
void stack_test () {
5
 
  Test.add_func (VEE_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 (VEE_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 popped.");
35
 
    }
36
 
    
37
 
  });
38
 
 
39
 
 
40
 
  Test.add_func (VEE_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 expected value.");
48
 
    }
49
 
 
50
 
    if (stk.pop () != 1337) {
51
 
      Test.fail ();
52
 
      Test.message ("Popped 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: Experted %i, get %i.",
64
 
                       i, got_val);
65
 
      }
66
 
    }
67
 
 
68
 
  });
69
 
}