File: 05stack.t

package info (click to toggle)
libhtml-widgets-navmenu-perl 1.1000-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 636 kB
  • sloc: perl: 8,051; makefile: 9
file content (66 lines) | stat: -rw-r--r-- 2,572 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/perl -w

use Test::More tests => 23;

use strict;

BEGIN
{
    use_ok('HTML::Widgets::NavMenu::Tree::Iterator::Stack');    # TEST
}

{
    my $stack = HTML::Widgets::NavMenu::Tree::Iterator::Stack->new();
    ok( $stack, "Checking for Object Allocation" );             # TEST
    is( $stack->len(), 0, "len() == 0 on allocation" );         # TEST
    ok( $stack->is_empty(), "is_empty() on allocation" );       # TEST
    $stack->push("Hello");
    $stack->push("World");

    # TEST
    ok( ( !$stack->is_empty() ), "is_empty() is not true after filling" );
    $stack->push("TamTam");
    is( $stack->len(),   3,        "Checking stack len" );           # TEST
    is( $stack->top(),   "TamTam", "Checking top of stack" );        # TEST
    is( $stack->item(2), "TamTam", "Checking Item 2" );              # TEST
    is( $stack->item(1), "World",  "Checking Item 1" );              # TEST
    is( $stack->item(0), "Hello",  "Checking Item 0" );              # TEST
    my $popped_item = $stack->pop();
    is( $popped_item,  "TamTam", "Popped Item" );                    # TEST
    is( $stack->len(), 2,        "Checking stack len" );             # TEST
                                                                     # TEST
    is( $stack->top(), "World",  "Checking stack top after pop" );
    $stack->push("Quatts");
    is( $stack->len(), 3,        "Stack Len" );                      # TEST
    is( $stack->top(), "Quatts", "Top Item is Quatts" );             # TEST
    $stack->pop();
    $stack->pop();
    $stack->pop();

    # TEST
    ok( ( !defined( $stack->top() ) ),
        "Checking for top() returning undef on empty stack" );
    is( $stack->len(), 0, "len() == 0 after popping all elements" );      # TEST
    ok( $stack->is_empty(), "is_empty() after popping all elements" );    # TEST
}

{
    my $stack = HTML::Widgets::NavMenu::Tree::Iterator::Stack->new();
    $stack->push("Hello");
    $stack->push("Superb");
    $stack->push("Quality");
    $stack->push("Pardon");
    $stack->reset();
    is( $stack->len(), 0, "len() == 0 after reset" );                     # TEST
    ok( $stack->is_empty(), "is_empty() after reset" );                   # TEST
                                                                          # TEST
    ok( ( !defined( $stack->top() ) ),
        "Checking for top() returning undef on reset stack" );
    $stack->push("Condor");

    # TEST
    is( $stack->len(), 1, "len() after push() after reset" );

    # TEST
    is( $stack->item(0), "Condor", "Stack is correct after push after reset" );
}