summaryrefslogtreecommitdiff
path: root/tikzit-old/src/common/test/color.m
blob: 48a6ff436a35a3554001370f826fa72b9c3c39e2 (plain)
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
//
//  color.m
//  TikZiT
//  
//  Copyright 2010 Aleks Kissinger. All rights reserved.
//  
//  
//  This file is part of TikZiT.
//  
//  TikZiT 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 3 of the License, or
//  (at your option) any later version.
//  
//  TikZiT 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 TikZiT.  If not, see <http://www.gnu.org/licenses/>.
//  
#import "test/test.h"
#import "ColorRGB.h"

#ifdef STAND_ALONE
void runTests() {
#else
void testColor() {
#endif
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	startTestBlock(@"color");
	
	ColorRGB *red = [ColorRGB colorWithRed:255 green:0 blue:0];
	ColorRGB *lime = [ColorRGB colorWithRed:0 green:255 blue:0];
	ColorRGB *green = [ColorRGB colorWithRed:0 green:128 blue:0];
	TEST(@"Recognised red",
		 [red name] != nil &&
		 [[red name] isEqualToString:@"Red"]);
	TEST(@"Recognised lime",
		 [lime name] != nil &&
		 [[lime name] isEqualToString:@"Lime"]);
	TEST(@"Recognised green",
		 [green name] != nil &&
		 [[green name] isEqualToString:@"Green"]);
	
	ColorRGB *floatRed = [ColorRGB colorWithFloatRed:1.0f green:0.0f blue:0.0f];
	ColorRGB *floatLime = [ColorRGB colorWithFloatRed:0.0f green:1.0f blue:0.0f];
	ColorRGB *floatGreen = [ColorRGB colorWithFloatRed:0.0f green:0.5f blue:0.0f];
	
	TEST(@"Float red equal to int red", [floatRed isEqual:red]);
	TEST(@"Float lime equal to int lime", [floatLime isEqual:lime]);
	TEST(@"Float green equal to int green", [floatGreen isEqual:green]);
	
	TEST(@"Recognised float red",
		 [floatRed name] != nil &&
		 [[floatRed name] isEqualToString:@"Red"]);
	
	TEST(@"Recognised float lime",
		 [floatLime name] != nil &&
		 [[floatLime name] isEqualToString:@"Lime"]);
	
	TEST(@"Recognised float green",
		 [floatGreen name] != nil &&
		 [[floatGreen name] isEqualToString:@"Green"]);
	
	[floatRed setRedFloat:0.99f];
	TEST(@"Nudged red, not recognised now", [floatRed name] == nil);
	[floatRed setToClosestHashed];
	TEST(@"Set to closest hashed, reconised again",
		 [floatRed name] != nil &&
		 [[floatRed name] isEqualToString:@"Red"]);
	
	TEST(@"Red has correct hex (ff0000)", [[red hexName] isEqualToString:@"hexcolor0xff0000"]);
	TEST(@"Lime has correct hex (00ff00)", [[lime hexName] isEqualToString:@"hexcolor0x00ff00"]);
	TEST(@"Green has correct hex (008000)", [[green hexName] isEqualToString:@"hexcolor0x008000"]);
	
	endTestBlock(@"color");
	[pool drain];
}