/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: 2024-12-21 22:39:17 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20241221223917-jbt2ylyz9nxjss49
various changes
[utils/utils.vala]
* Removed uneeded int32_abs function

[utils/stack]
* more informative error when trying to pop an empty stack.

[utils/random.vala]
* added c_names to functions (probobly not needed).

[utils/pair.vala]
* Made compact
* made FreeFunc delegates unowned to fix error
* added constructor Pair.with_free_func ().

[utils/named_vector.vala]
* made class compact.

[utils/meson.build]
* Reordered files in list
* added logger.vala.

[utils/logger.vala]
* Added fast and easy logger class.

[utils/fast_number.vala]
* added a bunch of cname CCode attributes.

[general]
* Spelling in comments and functions.

[meson.build]
* Made dependancies easier to read
* added vala posix dependency

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
}