summaryrefslogtreecommitdiff
path: root/SmartDeviceLinkTests/DevAPISpecs/NSArray+ExtensionsSpec.m
blob: 7a8bf127734830573896991ed370b5d28ca250f2 (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
//
//  NSArray+ExtensionsSpec.m
//  SmartDeviceLinkTests
//
//  Created by Joel Fischer on 2/22/21.
//  Copyright © 2021 smartdevicelink. All rights reserved.
//

#import "NSArray+Extensions.h"

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

QuickSpecBegin(NSArray_ExtensionsSpec)

describe(@"checking the dynamic hash of an array", ^{
    __block NSArray *testArray = nil;

    beforeEach(^{
        testArray = nil;
    });

    context(@"when the array has no objects", ^{
        beforeEach(^{
            testArray = @[];
        });

        it(@"should return a dynamic hash of 0", ^{
            expect(testArray.dynamicHash).to(equal(0));
        });
    });

    context(@"when the array contains one string", ^{
        beforeEach(^{
            testArray = @[@"test string"];
        });

        it(@"should return a consistent dynamic hash", ^{
            expect(testArray.dynamicHash).to(equal(testArray.dynamicHash));
        });

        it(@"should return a different hash than the normal hash function", ^{
            expect(testArray.dynamicHash).toNot(equal(testArray.hash));
        });
    });

    context(@"when the array contains multiple strings", ^{
        it(@"should return different numbers depending on where the strings are in the array", ^{
            testArray = @[@"test string", @"test string 2"];
            NSUInteger hash1 = testArray.dynamicHash;

            testArray = @[@"test string 2", @"test string"];
            NSUInteger hash2 = testArray.dynamicHash;

            expect(hash1).toNot(equal(hash2));
        });
    });
});

QuickSpecEnd