Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 92 lines (83 sloc) 2.972 kb
7e0605c Bradley Grainger Add GetPersistentHashCode for bool, int, long, string.
bgrainger authored
1 using NUnit.Framework;
b99a0fe Bradley Grainger Added tests to verify that overloads produce correct output.
bgrainger authored
2
3 namespace Logos.Utility.Tests
4 {
5 [TestFixture]
6 public class HashCodeUtilityTests
7 {
8 [TestCase(0)]
9 [TestCase(1)]
10 [TestCase(int.MinValue)]
11 [TestCase(int.MaxValue)]
12 public void HashOne(int value)
13 {
14 Assert.That(HashCodeUtility.CombineHashCodes(value), Is.EqualTo(HashCodeUtility.CombineHashCodes(new[] { value })));
15 }
16
17 [TestCase(0, 0)]
18 [TestCase(int.MinValue, int.MaxValue)]
19 [TestCase(0, -1)]
20 public void HashTwo(int value1, int value2)
21 {
22 Assert.That(HashCodeUtility.CombineHashCodes(value1, value2), Is.EqualTo(HashCodeUtility.CombineHashCodes(new[] { value1, value2 })));
23 }
24
25 [TestCase(0, 0, 0)]
26 [TestCase(int.MinValue, 0, int.MaxValue)]
27 [TestCase(1, 2, 3)]
28 public void HashThree(int value1, int value2, int value3)
29 {
30 Assert.That(HashCodeUtility.CombineHashCodes(value1, value2, value3), Is.EqualTo(HashCodeUtility.CombineHashCodes(new[] { value1, value2, value3 })));
31 }
32
33 [TestCase(0, 0, 0, 0)]
34 [TestCase(int.MinValue, 0, int.MaxValue, -1)]
35 [TestCase(1, 2, 3, 4)]
36 public void HashFour(int value1, int value2, int value3, int value4)
37 {
38 Assert.That(HashCodeUtility.CombineHashCodes(value1, value2, value3, value4), Is.EqualTo(HashCodeUtility.CombineHashCodes(new[] { value1, value2, value3, value4 })));
39 }
7e0605c Bradley Grainger Add GetPersistentHashCode for bool, int, long, string.
bgrainger authored
40
41 [TestCase(false, 1800329511)]
42 [TestCase(true, -1266253386)]
43 public void GetPersistentBoolHashCode(bool value, int expected)
44 {
45 Assert.That(HashCodeUtility.GetPersistentHashCode(value), Is.EqualTo(expected));
46 }
47
48 [TestCase(0, 1800329511)]
49 [TestCase(1, -1266253386)]
50 [TestCase(2, -496519092)]
51 [TestCase(3, 1332612764)]
52 [TestCase(4, 946348061)]
53 [TestCase(-1, -26951294)]
54 [TestCase(-2, 2115881666)]
55 public void GetPersistentIntHashCode(int value, int expected)
56 {
57 Assert.That(HashCodeUtility.GetPersistentHashCode((sbyte) value), Is.EqualTo(expected));
58 Assert.That(HashCodeUtility.GetPersistentHashCode((short) value), Is.EqualTo(expected));
59 if (value >= 0)
60 Assert.That(HashCodeUtility.GetPersistentHashCode((char) value), Is.EqualTo(expected));
61 Assert.That(HashCodeUtility.GetPersistentHashCode(value), Is.EqualTo(expected));
62 }
63
64 [TestCase(0, 720020139)]
65 [TestCase(1, 357654460)]
66 [TestCase(2, 715307540)]
67 [TestCase(3, 1072960876)]
68 [TestCase(4, 1430614333)]
69 [TestCase(-1, 532412650)]
70 [TestCase(-2, 340268856)]
71 public void GetPersistentLongHashCode(long value, int expected)
72 {
73 Assert.That(HashCodeUtility.GetPersistentHashCode(value), Is.EqualTo(expected));
74 }
75
76 [TestCase("", 0)]
77 [TestCase(null, 0)]
78 [TestCase("a", -889528276)]
79 [TestCase("b", -685344420)]
80 [TestCase("c", -414938692)]
81 [TestCase("abc", 2058321224)]
82 [TestCase("abcabc", 120553164)]
83 [TestCase("abcabca", 451022788)]
84 [TestCase("\" \"", 1671599841)]
85 [TestCase("#@!", 1671599841)]
86 public void GetPersistentHash(string value, int expected)
87 {
88 Assert.That(HashCodeUtility.GetPersistentHashCode(value), Is.EqualTo(expected));
89 }
b99a0fe Bradley Grainger Added tests to verify that overloads produce correct output.
bgrainger authored
90 }
91 }
Something went wrong with that request. Please try again.