forked from joecannatti/Objective-C-Koans
-
Notifications
You must be signed in to change notification settings - Fork 2
/
AboutValueAssertions.m
102 lines (76 loc) · 2.63 KB
/
AboutValueAssertions.m
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
//
// AboutAssertions.m
// ObjectiveCKoans
//
// Created by Joe Cannatti on 12/23/10.
// Copyright 2010 Puppy Sound Software. All rights reserved.
//
#import "Kiwi.h"
SPEC_BEGIN(AboutValueAssertions)
describe(@"Value Assertions", ^{
it(@"can assert truth", ^{
[[theValue(NO) should] beTrue];
});
it(@"can assert lies", ^{
[[theValue(YES) should] beFalse];
});
context(@"can assert equality", ^{
__block int actualValue;
beforeEach(^{
actualValue = 1 + 1;
});
it(@"in an ugly way", ^{
[[theValue(actualValue == 3) should] beTrue];
});
it(@"in a pretty way", ^{
[[theValue(actualValue) should] equal:theValue(3)];
});
});
it(@"can assert that a variable contains nil", ^{
NSObject *object = [NSObject new];
[object shouldBeNil];
});
it(@"can assert that a variable does not contains nil", ^{
NSObject *object = nil;
[object shouldNotBeNil];
});
it(@"can assert that two objects are equal", ^{
[[@"Panda" should] equal:@"Panda1"];
});
it(@"can assert that two objects are not equal", ^{
[[@"Panda" shouldNot] equal:@"Panda"];
});
it(@"can assert that floating point values are equal within a delta", ^{
//NOTE: float vs double precsion is what makes this fail
[[theValue(22.0f/7.0f) should] equal:(22.0/7.0) withDelta:0.000f];
});
it(@"can assert that a value is within a range", ^{
[[theValue(4) should] beWithin:theValue(4) of:theValue(9)];
});
it(@"can assert that a value is less than another value", ^{
[[theValue(4) should] beLessThan:theValue(4)];
});
it(@"can assert that a value is greater than another value", ^{
[[theValue(4) should] beGreaterThan:theValue(4)];
});
it(@"can assert that a value is less than or equal to another value", ^{
[[theValue(4) should] beLessThanOrEqualTo:theValue(3)];
});
it(@"can assert that a value is greater than or equal to another value", ^{
[[theValue(4) should] beGreaterThanOrEqualTo:theValue(5)];
});
it(@"can assert that a value is between to values", ^{
[[theValue(4) should] beBetween:theValue(5) and:theValue(6)];
});
it(@"can assert two variable contain the same pointer", ^{
//IdenticalTo checks for identical pointers
//but the compiler is smart about this and will use the same object if you do:
//NSString *panda = @"panda";
//NSString *samePanda = @"panda";
//mutableCopy is called to force a new instance and fail the test
NSString *panda = @"panda";
NSString *samePanda = [panda mutableCopy];
[[panda should] beIdenticalTo:samePanda];
});
});
SPEC_END