feisty meow concerns codebase 2.140
test_set.cpp
Go to the documentation of this file.
1/*****************************************************************************\
2* *
3* Name : test_set *
4* Author : Chris Koeritz *
5* *
6*******************************************************************************
7* Copyright (c) 1995-$now By Author. This program is free software; you can *
8* redistribute it and/or modify it under the terms of the GNU General Public *
9* License as published by the Free Software Foundation; either version 2 of *
10* the License or (at your option) any later version. This is online at: *
11* http://www.fsf.org/copyleft/gpl.html *
12* Please send any updates to: fred@gruntose.com *
13\*****************************************************************************/
14
16#include <basis/guards.h>
19#include <structures/set.h>
21#include <unit_test/unit_base.h>
22
23using namespace application;
24using namespace basis;
25using namespace loggers;
26using namespace mathematics;
27using namespace structures;
28using namespace textual;
29using namespace timely;
30using namespace unit_test;
31
32class test_set : virtual public unit_base, virtual public application_shell
33{
34public:
35 test_set() {}
36 DEFINE_CLASS_NAME("test_set");
37 virtual int execute();
38};
39
40int test_set::execute()
41{
42 FUNCDEF("execute");
43 int_set fred;
44 ASSERT_TRUE(fred.empty(), "first empty check should work");
45 ASSERT_TRUE(fred.add(23), "fred 1st add should go in");
46 ASSERT_TRUE(fred.add(90123), "fred 2nd add should be okay");
47 ASSERT_FALSE(fred.add(23), "fred 3rd add works fine");
48 ASSERT_FALSE(fred.add(90123), "fred 4th add is good");
49 ASSERT_FALSE(fred.empty(), "second empty check should work");
50 ASSERT_TRUE(fred.non_empty(), "non_empty check should be right");
51
52 int_set gen;
53 ASSERT_TRUE(gen.add(13), "gen 1st add is okay");
54 ASSERT_TRUE(gen.add(23), "gen 2nd add should be fine");
55 ASSERT_TRUE(gen.add(8012), "gen 3rd add was good");
56
57 int_set intersect(gen.intersection(fred));
58 ASSERT_EQUAL(intersect.elements(), 1, "intersection elements should be one");
59 ASSERT_TRUE(intersect.member(23), "element should be present as 23");
60
61 int_set uni(gen.set_union(fred));
62 ASSERT_EQUAL(uni.elements(), 4, "union elements should be correct");
63 ASSERT_TRUE(uni.member(23), "first element we seek should be present");
64 ASSERT_TRUE(uni.member(90123), "second element we seek should be present");
65 ASSERT_TRUE(uni.member(13), "third element we seek should be present");
66 ASSERT_TRUE(uni.member(8012), "fourth element we seek should be present");
67
68 return final_report();
69}
70
72
73HOOPLE_MAIN(test_set, )
74
The application_shell is a base object for console programs.
virtual int execute()=0
< retrieves the command line from the /proc hierarchy on linux.
A simple object that wraps a templated set of ints.
Definition set.h:156
set set_union(const set &union_with) const
Implements the set union of "this" with "union_with".
Definition set.h:277
set intersection(const set &intersect_with) const
Returns the intersection of "this" with the set in "intersect_with".
Definition set.h:260
bool add(const contents &to_add)
Adds a new element "to_add" to the set.
Definition set.h:232
bool non_empty() const
Returns true if the set has some elements.
Definition set.h:52
bool empty() const
Returns true if the set has no elements.
Definition set.h:50
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition enhance_cpp.h:42
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition enhance_cpp.h:54
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition hoople_main.h:61
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
Definition array.h:30
A logger that sends to the console screen using the standard output device.
An extension to floating point primitives providing approximate equality.
Definition averager.h:21
A dynamic container class that holds any kind of object via pointers.
Definition amorph.h:55
#include <time.h>
Useful support functions for unit testing, especially within hoople.
Definition unit_base.cpp:35
#define ASSERT_EQUAL(a, b, test_name)
Definition unit_base.h:38
#define ASSERT_TRUE(a, test_name)
Definition unit_base.h:46
#define ASSERT_FALSE(a, test_name)
Definition unit_base.h:50