The best way I've found to test this is to check 1000 or so different times and record each time it succeeds. Ultimately, you really want to know that the test runs for 98-99% of the time, while the result is ~ 99% +/- 1%. You must be good and the test must always pass.
- the shuffled hand should not match the original.
- the length of both should be the same.
- the sum of all cards must be the same (or similar).
swift code example:
func testShuffled() { var hand1 = [3,4,5,6,7,1,2,8,9,10,11,12,2,3,4,5,6,7,8,9,10,11,12] var count = 0 for _ in 0..<1000 { let hand2 = hand1.shuffled() if (hand1 != hand2 && hand1.count == hand2.count && hand1.reduce(0, combine: +) == hand2.reduce(0, combine: +)) { count += 1 } hand1 = hand2 } let result = Double(count) / 1000.00 XCTAssertEqualWithAccuracy(result, 1, accuracy: 0.02) }
source share