summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkTests/UtilitiesSpecs/Touches/CGPointUtilSpec.m
blob: f4c227291b58483262592d945075ebdb75020df1 (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
//
//  CGPointUtilSpec.m
//  SmartDeviceLink-iOS
//
//  Created by Muller, Alexander (A.) on 7/1/16.
//  Copyright © 2016 smartdevicelink. All rights reserved.
//

#import <Foundation/Foundation.h>

#import <Quick/Quick.h>
#import <Nimble/Nimble.h>
#import <OCMock/OCMock.h>

#import "CGPoint_Util.h"

QuickSpecBegin(CGPointUtilSpec)

describe(@"CGPoint_Util Tests", ^{
    __block CGPoint first;
    __block CGPoint second;
    context(@"For two positive points", ^{
        beforeEach(^{
            first = CGPointMake(100, 200);
            second = CGPointMake(300, 400);
        });
        
        it(@"should properly calculate the center between points", ^{
            CGPoint center = CGPointCenterOfPoints(first, second);
            expect(@(center.x)).to(equal(@200));
            expect(@(center.y)).to(equal(@300));
        });
        it(@"should properly calculate the distance between points", ^{
            CGFloat distance = CGPointDistanceBetweenPoints(first, second);
            expect(@(distance)).to(beCloseTo(@282.8427).within(0.0001));
        });
    });
    context(@"For two negative points", ^{
        beforeEach(^{
            first = CGPointMake(-100, -200);
            second = CGPointMake(-300, -400);
        });
        
        it(@"should properly calculate the center between points", ^{
            CGPoint center = CGPointCenterOfPoints(first, second);
            expect(@(center.x)).to(equal(@(-200)));
            expect(@(center.y)).to(equal(@(-300)));
        });
        it(@"should properly calculate the distance between points", ^{
            CGFloat distance = CGPointDistanceBetweenPoints(first, second);
            expect(@(distance)).to(beCloseTo(@282.8427).within(0.0001));
        });
    });
    context(@"For one positive and one negative point", ^{
        beforeEach(^{
            first = CGPointMake(100, 200);
            second = CGPointMake(-300, -400);
        });
        
        it(@"should properly calculate the center between points", ^{
            CGPoint center = CGPointCenterOfPoints(first, second);
            expect(@(center.x)).to(equal(@(-100)));
            expect(@(center.y)).to(equal(@(-100)));
        });
        it(@"should properly calculate the distance between points", ^{
            CGFloat distance = CGPointDistanceBetweenPoints(first, second);
            expect(@(distance)).to(beCloseTo(@721.1103).within(0.0001));
        });
    });
});

QuickSpecEnd