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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
#include <wibble/config.h>
#include <wibble/operators.h>
using namespace std;
using namespace wibble::operators;
#include <wibble/tests/tut-wibble.h>
namespace tut {
struct operators_shar {};
TESTGRP( operators );
static set<int> mkset(int i1)
{
set<int> a; a.insert(i1); return a;
}
static set<int> mkset(int i1, int i2)
{
set<int> a; a.insert(i1); a.insert(i2); return a;
}
static set<int> mkset(int i1, int i2, int i3)
{
set<int> a; a.insert(i1); a.insert(i2); a.insert(i3); return a;
}
static set<int> mkset(int i1, int i2, int i3, int i4)
{
set<int> a; a.insert(i1); a.insert(i2); a.insert(i3); a.insert(i4); return a;
}
template<> template<>
void to::test< 1 >() {
set< int > a = mkset(4, 5);
set< int > b = mkset(5);
set< int > c = a & b;
ensure_equals( c.size(), 1u );
ensure( c.find( 4 ) == c.end() );
ensure( c.find( 5 ) != c.end() );
c = a | b;
ensure_equals( c.size(), 2u );
ensure( c.find( 4 ) != c.end() );
ensure( c.find( 5 ) != c.end() );
c = a - b;
ensure_equals( c.size(), 1u );
ensure( c.find( 4 ) != c.end() );
ensure( c.find( 5 ) == c.end() );
}
template<> template<>
void to::test< 2 >() {
set< int > a = mkset(4, 3);
set< int > b = mkset(5);
b |= 3;
ensure_equals( b.size(), 2u );
ensure( b.find( 2 ) == b.end() );
ensure( b.find( 3 ) != b.end() );
ensure( b.find( 4 ) == b.end() );
ensure( b.find( 5 ) != b.end() );
b |= a;
ensure_equals( b.size(), 3u );
ensure( b.find( 3 ) != b.end() );
ensure( b.find( 4 ) != b.end() );
ensure( b.find( 5 ) != b.end() );
b &= a;
ensure_equals( b.size(), 2u );
ensure( b.find( 3 ) != b.end() );
ensure( b.find( 4 ) != b.end() );
ensure( b.find( 5 ) == b.end() );
b.insert( b.begin(), 2 );
b -= a;
ensure_equals( b.size(), 1u );
ensure( b.find( 2 ) != b.end() );
ensure( b.find( 3 ) == b.end() );
ensure( b.find( 4 ) == b.end() );
}
template<> template<>
void to::test< 3 >() {
set< int > a;
a = a | wibble::Empty<int>();
ensure_equals( a.size(), 0u );
a = a | wibble::Singleton<int>(1);
ensure_equals( a.size(), 1u );
ensure( a.find( 1 ) != a.end() );
a = a - wibble::Empty<int>();
ensure_equals( a.size(), 1u );
ensure( a.find( 1 ) != a.end() );
a = a - wibble::Singleton<int>(1);
ensure_equals( a.size(), 0u );
ensure( a.find( 1 ) == a.end() );
a |= wibble::Empty<int>();
ensure_equals( a.size(), 0u );
a |= wibble::Singleton<int>(1);
ensure_equals( a.size(), 1u );
ensure( a.find( 1 ) != a.end() );
a -= wibble::Empty<int>();
ensure_equals( a.size(), 1u );
ensure( a.find( 1 ) != a.end() );
a -= wibble::Singleton<int>(1);
ensure_equals( a.size(), 0u );
ensure( a.find( 1 ) == a.end() );
}
template<> template<>
void to::test< 4 >() {
set< int > a, b;
ensure( a <= b );
ensure( b <= a );
}
template<> template<>
void to::test< 5 >() {
// Catches a past bug of in-place intersection that would delete too many
// items if the second set had items not present in the first
set<int> a = mkset(2);
set<int> b = mkset(1, 2);
set<int> c = mkset(2);
set<int> d = a & b;
ensure(c == d);
d = a;
d &= b;
ensure(c == d);
}
}
// vim:set ts=4 sw=4:
|