BGC Tools
Public Member Functions | Private Member Functions
BGC.Tests.ApplicationVersionTests Class Reference

Public Member Functions

void TestApplicationVersionFeatures ()
 

Private Member Functions

delegate bool VersionComparison (in ApplicationVersion lhs, in ApplicationVersion rhs)
 
delegate bool VersionUnitary (in ApplicationVersion value)
 

Detailed Description

Definition at line 12 of file ApplicationVersionTests.cs.

Member Function Documentation

◆ TestApplicationVersionFeatures()

void BGC.Tests.ApplicationVersionTests.TestApplicationVersionFeatures ( )
inline

Definition at line 18 of file ApplicationVersionTests.cs.

References BGC.Utility.ApplicationVersion.Build, BGC.Utility.ApplicationVersion.Major, BGC.Utility.ApplicationVersion.Minor, BGC.Utility.ApplicationVersion.Revision, and BGC.Utility.ApplicationVersion.ToString().

19  {
20  VersionComparison greaterThan = (in ApplicationVersion lhs, in ApplicationVersion rhs) => lhs > rhs;
21  VersionComparison greaterOrEq = (in ApplicationVersion lhs, in ApplicationVersion rhs) => lhs >= rhs;
22  VersionComparison lessThan = (in ApplicationVersion lhs, in ApplicationVersion rhs) => lhs < rhs;
23  VersionComparison lessOrEq = (in ApplicationVersion lhs, in ApplicationVersion rhs) => lhs <= rhs;
24 
25  VersionComparison equal = (in ApplicationVersion lhs, in ApplicationVersion rhs) => lhs == rhs;
26  VersionComparison notEqual = (in ApplicationVersion lhs, in ApplicationVersion rhs) => lhs != rhs;
27 
28  VersionUnitary isNull = (in ApplicationVersion value) => value.IsNull();
29 
30  //Test some implicitly created ApplicationVersions
31  //Test >
32  {
33  Assert.IsTrue(greaterThan("1.0.1", "0.999.123"));
34  Assert.IsFalse(greaterThan("9.99.999", "9.100.9999"));
35  Assert.IsTrue(greaterThan("10.0.0.1", "10"));
36  //Equality
37  Assert.IsFalse(greaterThan("123.456.7890", "123.456.7890"));
38  }
39 
40  //Test >=
41  {
42  Assert.IsTrue(greaterOrEq("1.0.1", "0.999.123"));
43  Assert.IsFalse(greaterOrEq("9.99.999", "9.100.9999"));
44  Assert.IsTrue(greaterOrEq("10.0.0.1", "10"));
45  //Equality
46  Assert.IsTrue(greaterOrEq("123.456.7890", "123.456.7890"));
47  }
48 
49  //Test <
50  {
51  Assert.IsFalse(lessThan("1.0.1", "0.999.123"));
52  Assert.IsTrue(lessThan("9.99.999", "9.100.9999"));
53  Assert.IsTrue(lessThan("10", "10.0.0.1"));
54  //Equality
55  Assert.IsFalse(lessThan("44.536.0", "44.536"));
56  }
57 
58  //Test <=
59  {
60  Assert.IsFalse(lessOrEq("1.0.1", "0.999.123"));
61  Assert.IsTrue(lessOrEq("9.99.999", "9.100.9999"));
62  Assert.IsTrue(lessOrEq("10", "10.0.0.1"));
63  //Equality
64  Assert.IsTrue(lessOrEq("44.536.0", "44.536"));
65  }
66 
67  //Test ==
68  {
69  Assert.IsFalse(equal("1.0.1", "0.999.123"));
70  Assert.IsFalse(equal("9.99.999", "9.100.9999"));
71  Assert.IsFalse(equal("10", "10.0.0.1"));
72  //Equality
73  Assert.IsTrue(equal("44.536.0", "44.536"));
74  }
75 
76  //Test !=
77  {
78  Assert.IsTrue(notEqual("1.0.1", "0.999.123"));
79  Assert.IsTrue(notEqual("9.99.999", "9.100.9999"));
80  Assert.IsTrue(notEqual("10.0.0.1", "10"));
81  //Equality
82  Assert.IsFalse(notEqual("123.456.7890", "123.456.7890"));
83  }
84 
85  //Test IsNull
86  {
87  Assert.IsFalse(isNull("1"));
88  Assert.IsFalse(isNull("9999.9999.9999.9999"));
89  Assert.IsFalse(isNull("3.2.1.1"));
90  Assert.IsTrue(isNull("0"));
91  Assert.IsTrue(isNull("0.0.0.0"));
92 
93  //Bad attempts
94 
95  string[] unparsableAttempts = new string[]
96  {
97  "asdf",
98  "asdf.asdfas.gasdfga.*",
99  ""
100  };
101 
102  string[] truncatingAttempts = new string[] { "0.0.0.0.9" };
103 
104  //Error Handling
105  foreach (string version in unparsableAttempts)
106  {
107  UnityEngine.TestTools.LogAssert.Expect(LogType.Error, $"Failed to parse version string: {version}");
108  Assert.IsTrue(isNull(version));
109  }
110 
111  //Error Handling
112  foreach (string version in truncatingAttempts)
113  {
114  UnityEngine.TestTools.LogAssert.Expect(LogType.Error, $"ApplicationVersion constructed by string with more than 4 fields: \"{version}\"");
115  Assert.IsTrue(isNull(version));
116  }
117 
118  }
119 
120  //Test constructors
121  {
122  Assert.IsTrue(equal("44.536.0", new ApplicationVersion(44, 536)));
123  Assert.IsTrue(greaterOrEq("123.456.7890.1", new ApplicationVersion(123, 456, 7890)));
124  }
125 
126  //Test explicit fields
127  {
128  ApplicationVersion testVer = "10.0.1";
129 
130  Assert.IsTrue(testVer.Major == 10);
131  Assert.IsTrue(testVer.Minor == 0);
132  Assert.IsTrue(testVer.Build == 1);
133  Assert.IsTrue(testVer.Revision == 0);
134 
135  Assert.IsTrue(testVer.ToString() == "10.0.1");
136  }
137 
138  }
override string ToString()
delegate bool VersionUnitary(in ApplicationVersion value)
Sequence-based versioning parsing, managing, and comparing
delegate bool VersionComparison(in ApplicationVersion lhs, in ApplicationVersion rhs)
Here is the call graph for this function:

◆ VersionComparison()

delegate bool BGC.Tests.ApplicationVersionTests.VersionComparison ( in ApplicationVersion  lhs,
in ApplicationVersion  rhs 
)
private

◆ VersionUnitary()

delegate bool BGC.Tests.ApplicationVersionTests.VersionUnitary ( in ApplicationVersion  value)
private

The documentation for this class was generated from the following file: