File: SelectorTest.cc

package info (click to toggle)
steghide 0.5.1-14
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 3,432 kB
  • sloc: cpp: 13,302; ansic: 6,184; sh: 3,960; makefile: 384; yacc: 316; perl: 228; sed: 16
file content (93 lines) | stat: -rw-r--r-- 2,636 bytes parent folder | download | duplicates (3)
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
/*
 * steghide 0.5.1 - a steganography program
 * Copyright (C) 1999-2003 Stefan Hetzl <shetzl@chello.at>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

#include <vector>

#include "Selector.h"

#include "SelectorTest.h"
#include "TestCategoryCaller.h"

SelectorTest::SelectorTest (TestSuite* s)
	: UnitTest ("Selector", s)
{
	ADDTESTCATEGORY (SelectorTest, testIsPermutation) ;
	ADDTESTCATEGORY (SelectorTest, testIsIdentityPermutation) ;
}

void SelectorTest::setup ()
{
	s1 = new Selector (10, "a passphrase") ;
	s2 = new Selector (50, "another passphrase") ;
	s3 = new Selector (10000, "a large Selector object") ;
	s4 = new Selector (128, "a smaller object again") ;
	sid1 = new Selector (16) ;
	sid2 = new Selector (1234) ;
}

void SelectorTest::cleanup ()
{
	delete s1 ; delete s2 ; delete s3 ; delete s4 ;
	delete sid1 ; delete sid2 ;
}

void SelectorTest::testIsPermutation ()
{
	addTestResult (genericTestIsPermutation (s1)) ;
	addTestResult (genericTestIsPermutation (s2)) ;
	addTestResult (genericTestIsPermutation (s3)) ;
	addTestResult (genericTestIsPermutation (s4)) ;
}

void SelectorTest::testIsIdentityPermutation ()
{
	addTestResult (genericTestIsIdentityPermutation (sid1)) ;
	addTestResult (genericTestIsIdentityPermutation (sid2)) ;
}

bool SelectorTest::genericTestIsPermutation (Selector* s)
{
	std::vector<bool> hasoccurred (s->getRange()) ; // all set to false

	bool range_ok = true ;
	bool inj = true ;
	for (UWORD32 i = 0 ; i < s->getRange() ; i++) {
		UWORD32 value = (*s)[i] ;
		range_ok = (value < s->getRange()) && range_ok ;
		inj = !hasoccurred[value] && inj ;
		hasoccurred[value] = true ;
	}

	bool surj = true ;
	for (UWORD32 i = 0 ; i < s->getRange() ; i++) {
		surj = hasoccurred[i] && surj ;
	}

	return range_ok && inj && surj ;
}

bool SelectorTest::genericTestIsIdentityPermutation (Selector* s)
{
	bool ok = true ;
	for (UWORD32 i = 0 ; i < s->getRange() ; i++) {
		ok = ((*s)[i] == i) && ok ;
	}
	return ok ;
}