forked from natikgadzhi/XNMaths
-
Notifications
You must be signed in to change notification settings - Fork 1
/
XNVectorTest.m
88 lines (64 loc) · 2.52 KB
/
XNVectorTest.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
//
// XNVectorTest.m
// Assignation 3.2
//
// Created by Нат Гаджибалаев on 17.11.09.
// Copyright 2009 Нат Гаджибалаев. All rights reserved.
//
#import "XNVectorTest.h"
#import "XNVector.h"
@implementation XNVectorTest
- (void) testTrue
{
STAssertTrue( YES, @"is not true" );
}
- (void) testXNVectorCanBeAllocatedAndIsFilledByZeros
{
NSUInteger testCapacity = 4l;
XNVector *vector = [[XNVector alloc] initWithCapacity:testCapacity];
STAssertEquals(vector.capacity, testCapacity, @"Capacity (%d) of the vector is wrong, should be %d",
vector.capacity, testCapacity);
for( NSUInteger i = 0; i < vector.capacity; i++){
STAssertEquals( [vector valueAtIndex:i], 0.0f,
@"Value %f at index %d in the vector seems to be uncleared during init.",
[vector valueAtIndex: i], i);
}
}
- (void) testXNVectorCanBeCretedWithMutableArray
{
NSUInteger testCapacity = 4l;
NSMutableArray *testVertices = [NSMutableArray arrayWithCapacity:testCapacity];
for( NSUInteger i = 0; i < testCapacity; i++){
[testVertices addObject:[ NSNumber numberWithFloat: (i * 2.5f)]];
}
XNVector *vector = [[XNVector alloc] initWithMutableArray: testVertices];
STAssertEquals( [vector valueAtIndex:3], 7.5f, @"Value at index 3 should be 7.5, but was %f", [vector valueAtIndex: 3]);
}
- (void) testCanBeFilledInWithInit
{
CGFloat filledWith[4] = { 0.0f, 1.0f, 4.0f, 3.0f };
XNVector *vector = [[XNVector alloc] initWithCapacity: 4 filledWith: filledWith];
STAssertEquals( [vector valueAtIndex:3], 3.0f, @"Value at index 3 should be equal to 3.0f, but was %f", [vector valueAtIndex:3] );
}
- (void) testThrowsOnBadIndex
{
NSUInteger testCapacity = 4l;
XNVector *vector = [[XNVector alloc] initWithCapacity:testCapacity];
STAssertThrows([vector valueAtIndex: 10], @"Should throw an error when trying to access a vertice out of the dimensions");
STAssertThrows([vector setValue: 3.0f atIndex: 10], @"Should throw an error when writing a vertice out of the dimensions");
}
- (void) testSetsValue
{
NSUInteger testCapacity = 4l;
XNVector *vector = [[XNVector alloc] initWithCapacity:testCapacity];
[vector setValue: 5.0f atIndex: 1];
STAssertEquals( [vector valueAtIndex: 1], 5.0f, @"Value should be set correctly, but it's %f, not 5f", [vector valueAtIndex: 1]);
}
- (void) testNorm
{
CGFloat vectorData[] = { 5, 6, 3, 5, 2, 1 };
XNVector *vector = [[XNVector alloc] initWithCapacity: 6 filledWith: &vectorData];
STAssertEquals( [vector norm], 10.0f, @"Wrong vector norm.");
}
// test something more complex.
@end