summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPNTests/MullvadREST/Extensions/UIntTests.swift
blob: 2f581d227ec40a012fdd99c29a9122dbc7863805 (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
//
//  UIntTests.swift
//  MullvadVPN
//
//  Created by Jon Petersson on 2024-11-05.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import XCTest

@testable import MullvadREST

class UIntTests: XCTestCase {
    func testCountingSets() {
        for setSize in UInt(1)..<20 {
            let sampleSize: UInt = (setSize * 2) - 1

            var count: UInt = 0
            (UInt(0)...sampleSize).forEach { index in
                count = count == setSize ? 1 : count + 1

                let lowerHalfCount = count - 1
                let upperHalfCount = lowerHalfCount + setSize

                XCTAssertEqual(
                    index.isOrdered(nth: count, forEverySetOf: setSize),
                    index == lowerHalfCount || index == upperHalfCount
                )
            }
        }
    }
}