2 # vim:ts=4:sw=4:expandtab
4 use base 'Test::Builder::Module';
11 my $CLASS = __PACKAGE__;
15 i3test::Test - Additional test instructions for use in i3 testcases
21 my $ws = fresh_workspace;
22 is_num_children($ws, 0, 'no containers on this workspace yet');
24 is_num_children($ws, 1, 'one container after "open"');
30 This module provides convenience methods for i3 testcases. If you notice that a
31 certain pattern is present in 5 or more test cases, it should most likely be
32 moved into this module.
36 =head2 is_num_children($workspace, $expected, $test_name)
38 Gets the number of children on the given workspace and verifies that they match
39 the expected amount of children.
41 is_num_children('1', 0, 'no containers on workspace 1 at startup');
46 my ($workspace, $num_children, $name) = @_;
47 my $tb = $CLASS->builder;
49 my $con = i3test::get_ws($workspace);
50 $tb->ok(defined($con), "Workspace $workspace exists");
52 $tb->skip("Workspace does not exist, skipping is_num_children");
56 my $got_num_children = scalar @{$con->{nodes}};
58 $tb->is_num($got_num_children, $num_children, $name);
61 =head2 cmp_float($a, $b)
63 Compares floating point numbers C<$a> and C<$b> and returns true if they differ
66 $tmp = fresh_workspace;
68 open_window for (1..4);
70 cmd 'resize grow width 10 px or 25 ppt';
72 ($nodes, $focus) = get_ws_content($tmp);
73 ok(cmp_float($nodes->[0]->{percent}, 0.166666666666667), 'first window got 16%');
74 ok(cmp_float($nodes->[1]->{percent}, 0.166666666666667), 'second window got 16%');
75 ok(cmp_float($nodes->[2]->{percent}, 0.166666666666667), 'third window got 16%');
76 ok(cmp_float($nodes->[3]->{percent}, 0.50), 'fourth window got 50%');
80 my ($a, $b, $name) = @_;
81 my $tb = $CLASS->builder;
83 $tb->cmp_ok(abs($a - $b), '<', 1e-6, $name);
88 Michael Stapelberg <michael@i3wm.org>