first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / library / tests_structures / test_set.cpp
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
15 #include <application/hoople_main.h>
16 #include <basis/guards.h>
17 #include <loggers/console_logger.h>
18 #include <loggers/critical_events.h>
19 #include <structures/set.h>
20 #include <structures/static_memory_gremlin.h>
21 #include <unit_test/unit_base.h>
22
23 using namespace application;
24 using namespace basis;
25 using namespace loggers;
26 using namespace mathematics;
27 using namespace structures;
28 using namespace textual;
29 using namespace timely;
30 using namespace unit_test;
31
32 class test_set : virtual public unit_base, virtual public application_shell 
33 {
34 public:
35   test_set() {}
36   DEFINE_CLASS_NAME("test_set");
37   virtual int execute();
38 };
39
40 int 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
71 //////////////
72
73 HOOPLE_MAIN(test_set, )
74