Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 1 | // Licensed to the Apache Software Foundation(ASF) under one |
| 2 | // or more contributor license agreements.See the NOTICE file |
| 3 | // distributed with this work for additional information |
| 4 | // regarding copyright ownership.The ASF licenses this file |
| 5 | // to you under the Apache License, Version 2.0 (the |
| 6 | // "License"); you may not use this file except in compliance |
| 7 | // with the License. You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, |
| 12 | // software distributed under the License is distributed on an |
| 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | // KIND, either express or implied. See the License for the |
| 15 | // specific language governing permissions and limitations |
| 16 | // under the License. |
| 17 | |
| 18 | using System; |
| 19 | using System.Collections.Generic; |
| 20 | using System.Diagnostics; |
| 21 | using System.Linq; |
| 22 | using System.Text; |
| 23 | using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 24 | using OptReqDefTest; |
| 25 | using Thrift.Collections; |
| 26 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 27 | #nullable disable // this is just test code, we leave it at that |
| 28 | |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 29 | namespace Thrift.Tests.DataModel |
| 30 | { |
| 31 | // ReSharper disable once InconsistentNaming |
| 32 | [TestClass] |
| 33 | public class DeepCopyTests |
| 34 | { |
| 35 | [TestMethod] |
| 36 | public void Test_Complex_DeepCopy() |
| 37 | { |
| 38 | var first = InitializeInstance(new RaceDetails()); |
| 39 | VerifyIdenticalContent(first, InitializeInstance(new RaceDetails())); |
| 40 | |
| 41 | var second = first.DeepCopy(); |
| 42 | VerifyIdenticalContent(first, second); |
| 43 | ModifyInstance(second,0); |
| 44 | VerifyDifferentContent(first, second); |
| 45 | VerifyIdenticalContent(first, InitializeInstance(new RaceDetails())); |
| 46 | |
| 47 | var third = second.DeepCopy(); |
| 48 | VerifyIdenticalContent(second, third); |
| 49 | ModifyInstance(third,0); |
| 50 | VerifyDifferentContent(second, third); |
| 51 | VerifyIdenticalContent(first, InitializeInstance(new RaceDetails())); |
| 52 | } |
| 53 | |
| 54 | private RaceDetails MakeNestedRaceDetails(int nesting) |
| 55 | { |
| 56 | if (++nesting > 1) |
| 57 | return null; |
| 58 | |
| 59 | var instance = new RaceDetails(); |
| 60 | InitializeInstance(instance,nesting); |
| 61 | return instance; |
| 62 | } |
| 63 | |
| 64 | private jack MakeNestedUnion(int nesting) |
| 65 | { |
| 66 | if (++nesting > 1) |
| 67 | return null; |
| 68 | |
| 69 | var details = new RaceDetails(); |
| 70 | InitializeInstance(details,nesting); |
| 71 | return new jack.nested_struct(details); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | private RaceDetails InitializeInstance(RaceDetails instance, int nesting = 0) |
| 76 | { |
| 77 | // at init, we intentionally leave all non-required fields unset |
| 78 | Assert.IsFalse(instance.__isset.opt_one); |
| 79 | Assert.IsFalse(instance.__isset.opt_two); |
| 80 | Assert.IsFalse(instance.__isset.opt_three); |
| 81 | Assert.IsFalse(instance.__isset.opt_four); |
| 82 | Assert.IsFalse(instance.__isset.opt_five); |
| 83 | Assert.IsFalse(instance.__isset.opt_six); |
| 84 | Assert.IsFalse(instance.__isset.opt_seven); |
| 85 | Assert.IsFalse(instance.__isset.opt_eight); |
| 86 | |
| 87 | // set all required to null/default |
| 88 | instance.Req_one = default; |
| 89 | instance.Req_two = default; |
| 90 | instance.Req_three = default; |
| 91 | instance.Req_four = default; |
| 92 | instance.Req_five = default; |
| 93 | instance.Req_six = default; |
| 94 | instance.Req_seven = default;; |
| 95 | instance.Req_eight = default; |
| 96 | |
| 97 | // leave non-required fields unset again |
| 98 | Assert.IsFalse(instance.__isset.def_one); |
| 99 | Assert.IsFalse(instance.__isset.def_two); |
| 100 | Assert.IsFalse(instance.__isset.def_three); |
| 101 | Assert.IsFalse(instance.__isset.def_four); |
| 102 | Assert.IsFalse(instance.__isset.def_five); |
| 103 | Assert.IsFalse(instance.__isset.def_six); |
| 104 | Assert.IsFalse(instance.__isset.def_seven); |
| 105 | Assert.IsFalse(instance.__isset.def_eight); |
| 106 | |
| 107 | // these should have IDL defaults set |
| 108 | |
| 109 | Assert.IsTrue(instance.__isset.opt_one_with_value); |
| 110 | Assert.IsTrue(instance.__isset.opt_two_with_value); |
| 111 | Assert.IsTrue(instance.__isset.opt_three_with_value); |
| 112 | Assert.IsTrue(instance.__isset.opt_four_with_value); |
| 113 | Assert.IsTrue(instance.__isset.opt_five_with_value); |
| 114 | Assert.IsTrue(instance.__isset.opt_six_with_value); |
| 115 | Assert.IsTrue(instance.__isset.opt_seven_with_value); |
| 116 | Assert.IsTrue(instance.__isset.opt_eight_with_value); |
| 117 | |
| 118 | Assert.AreEqual(instance.Req_one_with_value, (Distance)1); |
| 119 | Assert.AreEqual(instance.Req_two_with_value, 2.22); |
| 120 | Assert.AreEqual(instance.Req_three_with_value, 3); |
| 121 | Assert.AreEqual(instance.Req_four_with_value, "four"); |
| 122 | Assert.AreEqual("five", Encoding.UTF8.GetString(instance.Req_five_with_value)); |
| 123 | |
| 124 | Assert.IsTrue(instance.Req_six_with_value.Count == 1); |
| 125 | Assert.AreEqual(instance.Req_six_with_value[0], 6 ); |
| 126 | |
| 127 | Assert.IsTrue(instance.Req_seven_with_value.Count == 1); |
| 128 | Assert.IsTrue(instance.Req_seven_with_value.Contains(7)); |
| 129 | |
| 130 | Assert.IsTrue(instance.Req_eight_with_value.Count == 1); |
| 131 | Assert.IsTrue(instance.Req_eight_with_value[8] == 8); |
| 132 | |
| 133 | Assert.IsTrue(instance.__isset.def_one_with_value); |
| 134 | Assert.IsTrue(instance.__isset.def_two_with_value); |
| 135 | Assert.IsTrue(instance.__isset.def_three_with_value); |
| 136 | Assert.IsTrue(instance.__isset.def_four_with_value); |
| 137 | Assert.IsTrue(instance.__isset.def_five_with_value); |
| 138 | Assert.IsTrue(instance.__isset.def_six_with_value); |
| 139 | Assert.IsTrue(instance.__isset.def_seven_with_value); |
| 140 | Assert.IsTrue(instance.__isset.def_eight_with_value); |
| 141 | |
| 142 | instance.Last_of_the_mohicans = true; |
| 143 | |
| 144 | if (nesting < 2) |
| 145 | { |
| 146 | instance.Far_list = new List<Distance>() { Distance.foo, Distance.bar, Distance.baz }; |
| 147 | instance.Far_set = new THashSet<Distance>() { Distance.foo, Distance.bar, Distance.baz }; |
| 148 | instance.Far_map = new Dictionary<Distance, Distance>() { [Distance.foo] = Distance.foo, [Distance.bar] = Distance.bar, [Distance.baz] = Distance.baz }; |
| 149 | |
| 150 | instance.Far_set_list = new THashSet<List<Distance>>() { new List<Distance>() { Distance.foo } }; |
| 151 | instance.Far_list_map_set = new List<Dictionary<sbyte, THashSet<Distance>>>() { new Dictionary<sbyte, THashSet<Distance>>() { [1] = new THashSet<Distance>() { Distance.baz } } }; |
| 152 | instance.Far_map_dist_to_rds = new Dictionary<Distance, List<RaceDetails>>() { [Distance.bar] = new List<RaceDetails>() { MakeNestedRaceDetails(nesting) } }; |
| 153 | |
| 154 | instance.Req_nested = MakeNestedRaceDetails(nesting); |
| 155 | Assert.IsFalse(instance.__isset.opt_nested); |
| 156 | Assert.IsFalse(instance.__isset.def_nested); |
| 157 | |
| 158 | instance.Req_union = MakeNestedUnion(nesting); |
| 159 | Assert.IsFalse(instance.__isset.opt_union); |
| 160 | Assert.IsFalse(instance.__isset.def_union); |
| 161 | } |
| 162 | |
| 163 | instance.Triplesix = (Distance)666; |
| 164 | |
| 165 | return instance; |
| 166 | } |
| 167 | |
| 168 | private void ModifyInstance(RaceDetails instance, int level) |
| 169 | { |
| 170 | if ((instance == null) || (++level > 4)) |
| 171 | return; |
| 172 | |
| 173 | instance.Opt_one = ModifyValue(instance.Opt_one); |
| 174 | instance.Opt_two = ModifyValue(instance.Opt_two); |
| 175 | instance.Opt_three = ModifyValue(instance.Opt_three); |
| 176 | instance.Opt_four = ModifyValue(instance.Opt_four); |
| 177 | instance.Opt_five = ModifyValue(instance.Opt_five); |
| 178 | instance.Opt_six = ModifyValue(instance.Opt_six); |
| 179 | instance.Opt_seven = ModifyValue(instance.Opt_seven); |
| 180 | instance.Opt_eight = ModifyValue(instance.Opt_eight); |
| 181 | |
| 182 | instance.Req_one = ModifyValue(instance.Req_one); |
| 183 | instance.Req_two = ModifyValue(instance.Req_two); |
| 184 | instance.Req_three = ModifyValue(instance.Req_three); |
| 185 | instance.Req_four = ModifyValue(instance.Req_four); |
| 186 | instance.Req_five = ModifyValue(instance.Req_five); |
| 187 | instance.Req_six = ModifyValue(instance.Req_six); |
| 188 | instance.Req_seven = ModifyValue(instance.Req_seven); |
| 189 | instance.Req_eight = ModifyValue(instance.Req_eight); |
| 190 | |
| 191 | instance.Def_one = ModifyValue(instance.Def_one); |
| 192 | instance.Def_two = ModifyValue(instance.Def_two); |
| 193 | instance.Def_three = ModifyValue(instance.Def_three); |
| 194 | instance.Def_four = ModifyValue(instance.Def_four); |
| 195 | instance.Def_five = ModifyValue(instance.Def_five); |
| 196 | instance.Def_six = ModifyValue(instance.Def_six); |
| 197 | instance.Def_seven = ModifyValue(instance.Def_seven); |
| 198 | instance.Def_eight = ModifyValue(instance.Def_eight); |
| 199 | |
| 200 | instance.Opt_one_with_value = ModifyValue(instance.Opt_one_with_value); |
| 201 | instance.Opt_two_with_value = ModifyValue(instance.Opt_two_with_value); |
| 202 | instance.Opt_three_with_value = ModifyValue(instance.Opt_three_with_value); |
| 203 | instance.Opt_four_with_value = ModifyValue(instance.Opt_four_with_value); |
| 204 | instance.Opt_five_with_value = ModifyValue(instance.Opt_five_with_value); |
| 205 | instance.Opt_six_with_value = ModifyValue(instance.Opt_six_with_value); |
| 206 | instance.Opt_seven_with_value = ModifyValue(instance.Opt_seven_with_value); |
| 207 | instance.Opt_eight_with_value = ModifyValue(instance.Opt_eight_with_value); |
| 208 | |
| 209 | instance.Req_one_with_value = ModifyValue(instance.Req_one_with_value); |
| 210 | instance.Req_two_with_value = ModifyValue(instance.Req_two_with_value); |
| 211 | instance.Req_three_with_value = ModifyValue(instance.Req_three_with_value); |
| 212 | instance.Req_four_with_value = ModifyValue(instance.Req_four_with_value); |
| 213 | instance.Req_five_with_value = ModifyValue(instance.Req_five_with_value); |
| 214 | instance.Req_six_with_value = ModifyValue(instance.Req_six_with_value); |
| 215 | instance.Req_seven_with_value = ModifyValue(instance.Req_seven_with_value); |
| 216 | instance.Req_eight_with_value = ModifyValue(instance.Req_eight_with_value); |
| 217 | |
| 218 | instance.Def_one_with_value = ModifyValue(instance.Def_one_with_value); |
| 219 | instance.Def_two_with_value = ModifyValue(instance.Def_two_with_value); |
| 220 | instance.Def_three_with_value = ModifyValue(instance.Def_three_with_value); |
| 221 | instance.Def_four_with_value = ModifyValue(instance.Def_four_with_value); |
| 222 | instance.Def_five_with_value = ModifyValue(instance.Def_five_with_value); |
| 223 | instance.Def_six_with_value = ModifyValue(instance.Def_six_with_value); |
| 224 | instance.Def_seven_with_value = ModifyValue(instance.Def_seven_with_value); |
| 225 | instance.Def_eight_with_value = ModifyValue(instance.Def_eight_with_value); |
| 226 | |
| 227 | instance.Last_of_the_mohicans = ModifyValue(instance.Last_of_the_mohicans); |
| 228 | |
| 229 | instance.Far_list = ModifyValue(instance.Far_list); |
| 230 | instance.Far_set = ModifyValue(instance.Far_set); |
| 231 | instance.Far_map = ModifyValue(instance.Far_map); |
| 232 | |
| 233 | instance.Far_set_list = ModifyValue(instance.Far_set_list); |
| 234 | instance.Far_list_map_set = ModifyValue(instance.Far_list_map_set); |
| 235 | instance.Far_map_dist_to_rds = ModifyValue(instance.Far_map_dist_to_rds, level); |
| 236 | |
| 237 | instance.Req_nested = ModifyValue(instance.Req_nested, level); |
| 238 | instance.Opt_nested = ModifyValue(instance.Opt_nested, level); |
| 239 | instance.Def_nested = ModifyValue(instance.Def_nested, level); |
| 240 | |
| 241 | instance.Req_union = ModifyValue(instance.Req_union, level); |
| 242 | instance.Opt_union = ModifyValue(instance.Opt_union, level); |
| 243 | instance.Def_union = ModifyValue(instance.Def_union, level); |
| 244 | |
| 245 | instance.Triplesix = ModifyValue(instance.Triplesix); |
| 246 | } |
| 247 | |
| 248 | private jack ModifyValue(jack value, int level) |
| 249 | { |
| 250 | if (++level > 4) |
| 251 | return value; |
| 252 | |
| 253 | if (value == null) |
| 254 | value = MakeNestedUnion(0); |
| 255 | Debug.Assert(value.As_nested_struct != null); |
| 256 | ModifyInstance(value.As_nested_struct, level); |
| 257 | return value; |
| 258 | } |
| 259 | |
| 260 | private RaceDetails ModifyValue(RaceDetails value, int level) |
| 261 | { |
| 262 | if (++level > 4) |
| 263 | return value; |
| 264 | |
| 265 | if (value == null) |
| 266 | value = new RaceDetails(); |
| 267 | ModifyInstance(value,level); |
| 268 | return value; |
| 269 | } |
| 270 | |
| 271 | private Dictionary<Distance, List<RaceDetails>> ModifyValue(Dictionary<Distance, List<RaceDetails>> value, int level) |
| 272 | { |
| 273 | if (value == null) |
| 274 | value = new Dictionary<Distance, List<RaceDetails>>(); |
| 275 | |
| 276 | if (++level > 4) |
| 277 | return value; |
| 278 | |
| 279 | var details = new RaceDetails(); |
| 280 | InitializeInstance(details); |
| 281 | value[Distance.foo] = new List<RaceDetails>() { details }; |
| 282 | |
| 283 | if (value.TryGetValue(Distance.bar, out var list) && (list.Count > 0)) |
| 284 | { |
| 285 | ModifyInstance(list[0], level); |
| 286 | list.Add(null); |
| 287 | } |
| 288 | |
| 289 | value[Distance.baz] = null; |
| 290 | |
| 291 | return value; |
| 292 | } |
| 293 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 294 | private static List<Dictionary<sbyte, THashSet<Distance>>> ModifyValue(List<Dictionary<sbyte, THashSet<Distance>>> value) |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 295 | { |
| 296 | if (value == null) |
| 297 | value = new List<Dictionary<sbyte, THashSet<Distance>>>(); |
| 298 | |
| 299 | if (value.Count == 0) |
| 300 | value.Add(new Dictionary<sbyte, THashSet<Distance>>()); |
| 301 | else |
| 302 | value.Add(null); |
| 303 | |
| 304 | sbyte key = (sbyte)(value[0].Count + 10); |
| 305 | if (value[0].Count == 0) |
| 306 | value[0].Add(key, new THashSet<Distance>()); |
| 307 | else |
| 308 | value[0].Add(key, null); |
| 309 | |
| 310 | foreach (var entry in value) |
| 311 | { |
| 312 | if (entry != null) |
| 313 | { |
| 314 | foreach (var pair in entry) |
| 315 | { |
| 316 | if (pair.Value != null) |
| 317 | { |
| 318 | if (pair.Value.Contains(Distance.baz)) |
| 319 | pair.Value.Remove(Distance.baz); |
| 320 | else |
| 321 | pair.Value.Add(Distance.baz); |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | return value; |
| 328 | } |
| 329 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 330 | private static THashSet<List<Distance>> ModifyValue(THashSet<List<Distance>> value) |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 331 | { |
| 332 | if (value == null) |
| 333 | value = new THashSet<List<Distance>>(); |
| 334 | |
| 335 | if (value.Count == 0) |
| 336 | value.Add(new List<Distance>()); |
| 337 | else |
| 338 | value.Add(null); |
| 339 | |
| 340 | foreach (var entry in value) |
| 341 | if( entry != null) |
| 342 | entry.Add(Distance.baz); |
| 343 | |
| 344 | return value; |
| 345 | } |
| 346 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 347 | private static Dictionary<Distance, Distance> ModifyValue(Dictionary<Distance, Distance> value) |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 348 | { |
| 349 | if (value == null) |
| 350 | value = new Dictionary<Distance, Distance>(); |
| 351 | value[Distance.foo] = value.ContainsKey(Distance.foo) ? ++value[Distance.foo] : Distance.foo; |
| 352 | value[Distance.bar] = value.ContainsKey(Distance.bar) ? ++value[Distance.bar] : Distance.bar; |
| 353 | value[Distance.baz] = value.ContainsKey(Distance.baz) ? ++value[Distance.baz] : Distance.baz; |
| 354 | return value; |
| 355 | } |
| 356 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 357 | private static THashSet<Distance> ModifyValue(THashSet<Distance> value) |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 358 | { |
| 359 | if (value == null) |
| 360 | value = new THashSet<Distance>(); |
| 361 | |
| 362 | if (value.Contains(Distance.foo)) |
| 363 | value.Remove(Distance.foo); |
| 364 | else |
| 365 | value.Add(Distance.foo); |
| 366 | |
| 367 | if (value.Contains(Distance.bar)) |
| 368 | value.Remove(Distance.bar); |
| 369 | else |
| 370 | value.Add(Distance.bar); |
| 371 | |
| 372 | if (value.Contains(Distance.baz)) |
| 373 | value.Remove(Distance.baz); |
| 374 | else |
| 375 | value.Add(Distance.baz); |
| 376 | |
| 377 | return value; |
| 378 | } |
| 379 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 380 | private static List<Distance> ModifyValue(List<Distance> value) |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 381 | { |
| 382 | if (value == null) |
| 383 | value = new List<Distance>(); |
| 384 | value.Add(Distance.foo); |
| 385 | value.Add(Distance.bar); |
| 386 | value.Add(Distance.baz); |
| 387 | return value; |
| 388 | } |
| 389 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 390 | private static bool ModifyValue(bool value) |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 391 | { |
| 392 | return !value; |
| 393 | } |
| 394 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 395 | private static Dictionary<sbyte, short> ModifyValue(Dictionary<sbyte, short> value) |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 396 | { |
| 397 | if (value == null) |
| 398 | value = new Dictionary<sbyte, short>(); |
| 399 | value.Add((sbyte)(value.Count + 10), (short)value.Count); |
| 400 | return value; |
| 401 | } |
| 402 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 403 | private static THashSet<long> ModifyValue(THashSet<long> value) |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 404 | { |
| 405 | if (value == null) |
| 406 | value = new THashSet<long>(); |
| 407 | value.Add(value.Count+100); |
| 408 | return value; |
| 409 | } |
| 410 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 411 | private static List<int> ModifyValue(List<int> value) |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 412 | { |
| 413 | if (value == null) |
| 414 | value = new List<int>(); |
| 415 | value.Add(value.Count); |
| 416 | return value; |
| 417 | } |
| 418 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 419 | private static byte[] ModifyValue(byte[] value) |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 420 | { |
| 421 | if (value == null) |
| 422 | value = new byte[1] { 0 }; |
| 423 | if (value.Length > 0) |
| 424 | value[0] = (value[0] < 0xFF) ? ++value[0] : (byte)0; |
| 425 | return value; |
| 426 | } |
| 427 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 428 | private static string ModifyValue(string value) |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 429 | { |
| 430 | return value + "1"; |
| 431 | } |
| 432 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 433 | private static double ModifyValue(double value) |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 434 | { |
| 435 | return value + 1.1; |
| 436 | } |
| 437 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 438 | private static short ModifyValue(short value) |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 439 | { |
| 440 | return ++value; |
| 441 | } |
| 442 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 443 | private static Distance ModifyValue(Distance value) |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 444 | { |
| 445 | return ++value; |
| 446 | } |
| 447 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 448 | private static void VerifyDifferentContent(RaceDetails first, RaceDetails second) |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 449 | { |
| 450 | Assert.AreNotEqual(first, second); |
| 451 | |
| 452 | Assert.AreNotEqual(first.Opt_two, second.Opt_two); |
| 453 | Assert.AreNotEqual(first.Opt_three, second.Opt_three); |
| 454 | Assert.AreNotEqual(first.Opt_four, second.Opt_four); |
| 455 | Assert.IsFalse(TCollections.Equals(first.Opt_five, second.Opt_five)); |
| 456 | Assert.IsFalse(TCollections.Equals(first.Opt_six, second.Opt_six)); |
| 457 | Assert.IsFalse(TCollections.Equals(first.Opt_seven, second.Opt_seven)); |
| 458 | Assert.IsFalse(TCollections.Equals(first.Opt_eight, second.Opt_eight)); |
| 459 | |
| 460 | Assert.AreNotEqual(first.Req_one, second.Req_one); |
| 461 | Assert.AreNotEqual(first.Req_two, second.Req_two); |
| 462 | Assert.AreNotEqual(first.Req_three, second.Req_three); |
| 463 | Assert.AreNotEqual(first.Req_four, second.Req_four); |
| 464 | Assert.IsFalse(TCollections.Equals(first.Req_five, second.Req_five)); |
| 465 | Assert.IsFalse(TCollections.Equals(first.Req_six, second.Req_six)); |
| 466 | Assert.IsFalse(TCollections.Equals(first.Req_seven, second.Req_seven)); |
| 467 | Assert.IsFalse(TCollections.Equals(first.Req_eight, second.Req_eight)); |
| 468 | |
| 469 | Assert.AreNotEqual(first.Def_one, second.Def_one); |
| 470 | Assert.AreNotEqual(first.Def_two, second.Def_two); |
| 471 | Assert.AreNotEqual(first.Def_three, second.Def_three); |
| 472 | Assert.AreNotEqual(first.Def_four, second.Def_four); |
| 473 | Assert.IsFalse(TCollections.Equals(first.Def_five, second.Def_five)); |
| 474 | Assert.IsFalse(TCollections.Equals(first.Def_six, second.Def_six)); |
| 475 | Assert.IsFalse(TCollections.Equals(first.Def_seven, second.Def_seven)); |
| 476 | Assert.IsFalse(TCollections.Equals(first.Def_eight, second.Def_eight)); |
| 477 | |
| 478 | Assert.AreNotEqual(first.Opt_one_with_value, second.Opt_one_with_value); |
| 479 | Assert.AreNotEqual(first.Opt_two_with_value, second.Opt_two_with_value); |
| 480 | Assert.AreNotEqual(first.Opt_three_with_value, second.Opt_three_with_value); |
| 481 | Assert.AreNotEqual(first.Opt_four_with_value, second.Opt_four_with_value); |
| 482 | Assert.IsFalse(TCollections.Equals(first.Opt_five_with_value, second.Opt_five_with_value)); |
| 483 | Assert.IsFalse(TCollections.Equals(first.Opt_six_with_value, second.Opt_six_with_value)); |
| 484 | Assert.IsFalse(TCollections.Equals(first.Opt_seven_with_value, second.Opt_seven_with_value)); |
| 485 | Assert.IsFalse(TCollections.Equals(first.Opt_eight_with_value, second.Opt_eight_with_value)); |
| 486 | |
| 487 | Assert.AreNotEqual(first.Req_one_with_value, second.Req_one_with_value); |
| 488 | Assert.AreNotEqual(first.Req_two_with_value, second.Req_two_with_value); |
| 489 | Assert.AreNotEqual(first.Req_three_with_value, second.Req_three_with_value); |
| 490 | Assert.AreNotEqual(first.Req_four_with_value, second.Req_four_with_value); |
| 491 | Assert.IsFalse(TCollections.Equals(first.Req_five_with_value, second.Req_five_with_value)); |
| 492 | Assert.IsFalse(TCollections.Equals(first.Req_six_with_value, second.Req_six_with_value)); |
| 493 | Assert.IsFalse(TCollections.Equals(first.Req_seven_with_value, second.Req_seven_with_value)); |
| 494 | Assert.IsFalse(TCollections.Equals(first.Req_eight_with_value, second.Req_eight_with_value)); |
| 495 | |
| 496 | Assert.AreNotEqual(first.Def_one_with_value, second.Def_one_with_value); |
| 497 | Assert.AreNotEqual(first.Def_two_with_value, second.Def_two_with_value); |
| 498 | Assert.AreNotEqual(first.Def_three_with_value, second.Def_three_with_value); |
| 499 | Assert.AreNotEqual(first.Def_four_with_value, second.Def_four_with_value); |
| 500 | Assert.IsFalse(TCollections.Equals(first.Def_five_with_value, second.Def_five_with_value)); |
| 501 | Assert.IsFalse(TCollections.Equals(first.Def_six_with_value, second.Def_six_with_value)); |
| 502 | Assert.IsFalse(TCollections.Equals(first.Def_seven_with_value, second.Def_seven_with_value)); |
| 503 | Assert.IsFalse(TCollections.Equals(first.Def_eight_with_value, second.Def_eight_with_value)); |
| 504 | |
| 505 | Assert.AreNotEqual(first.Last_of_the_mohicans, second.Last_of_the_mohicans); |
| 506 | |
| 507 | Assert.IsFalse(TCollections.Equals(first.Far_list, second.Far_list)); |
| 508 | Assert.IsFalse(TCollections.Equals(first.Far_set, second.Far_set)); |
| 509 | Assert.IsFalse(TCollections.Equals(first.Far_map, second.Far_map)); |
| 510 | |
| 511 | Assert.IsFalse(TCollections.Equals(first.Far_set_list, second.Far_set_list)); |
| 512 | Assert.IsFalse(TCollections.Equals(first.Far_list_map_set, second.Far_list_map_set)); |
| 513 | Assert.IsFalse(TCollections.Equals(first.Far_map_dist_to_rds, second.Far_map_dist_to_rds)); |
| 514 | |
| 515 | Assert.AreNotEqual(first.Req_nested, second.Req_nested); |
| 516 | Assert.AreNotEqual(first.Opt_nested, second.Opt_nested); |
| 517 | Assert.AreNotEqual(first.Def_nested, second.Def_nested); |
| 518 | |
| 519 | Assert.AreNotEqual(first.Req_union, second.Req_union); |
| 520 | Assert.AreNotEqual(first.Opt_union, second.Opt_union); |
| 521 | Assert.AreNotEqual(first.Def_union, second.Def_union); |
| 522 | |
| 523 | Assert.AreNotEqual(first.Triplesix, second.Triplesix); |
| 524 | } |
| 525 | |
Jens Geyer | 98a2325 | 2022-01-09 16:50:52 +0100 | [diff] [blame^] | 526 | private static void VerifyIdenticalContent(RaceDetails first, RaceDetails second) |
Jens Geyer | affea7b | 2020-05-22 17:28:30 +0200 | [diff] [blame] | 527 | { |
| 528 | Assert.AreEqual(first, second); |
| 529 | |
| 530 | Assert.AreEqual(first.Opt_two, second.Opt_two); |
| 531 | Assert.AreEqual(first.Opt_three, second.Opt_three); |
| 532 | Assert.AreEqual(first.Opt_four, second.Opt_four); |
| 533 | Assert.IsTrue(TCollections.Equals(first.Opt_five, second.Opt_five)); |
| 534 | Assert.IsTrue(TCollections.Equals(first.Opt_six, second.Opt_six)); |
| 535 | Assert.IsTrue(TCollections.Equals(first.Opt_seven, second.Opt_seven)); |
| 536 | Assert.IsTrue(TCollections.Equals(first.Opt_eight, second.Opt_eight)); |
| 537 | |
| 538 | Assert.AreEqual(first.Req_one, second.Req_one); |
| 539 | Assert.AreEqual(first.Req_two, second.Req_two); |
| 540 | Assert.AreEqual(first.Req_three, second.Req_three); |
| 541 | Assert.AreEqual(first.Req_four, second.Req_four); |
| 542 | Assert.IsTrue(TCollections.Equals(first.Req_five, second.Req_five)); |
| 543 | Assert.IsTrue(TCollections.Equals(first.Req_six, second.Req_six)); |
| 544 | Assert.IsTrue(TCollections.Equals(first.Req_seven, second.Req_seven)); |
| 545 | Assert.IsTrue(TCollections.Equals(first.Req_eight, second.Req_eight)); |
| 546 | |
| 547 | Assert.AreEqual(first.Def_one, second.Def_one); |
| 548 | Assert.AreEqual(first.Def_two, second.Def_two); |
| 549 | Assert.AreEqual(first.Def_three, second.Def_three); |
| 550 | Assert.AreEqual(first.Def_four, second.Def_four); |
| 551 | Assert.IsTrue(TCollections.Equals(first.Def_five, second.Def_five)); |
| 552 | Assert.IsTrue(TCollections.Equals(first.Def_six, second.Def_six)); |
| 553 | Assert.IsTrue(TCollections.Equals(first.Def_seven, second.Def_seven)); |
| 554 | Assert.IsTrue(TCollections.Equals(first.Def_eight, second.Def_eight)); |
| 555 | |
| 556 | Assert.AreEqual(first.Opt_one_with_value, second.Opt_one_with_value); |
| 557 | Assert.AreEqual(first.Opt_two_with_value, second.Opt_two_with_value); |
| 558 | Assert.AreEqual(first.Opt_three_with_value, second.Opt_three_with_value); |
| 559 | Assert.AreEqual(first.Opt_four_with_value, second.Opt_four_with_value); |
| 560 | Assert.IsTrue(TCollections.Equals(first.Opt_five_with_value, second.Opt_five_with_value)); |
| 561 | Assert.IsTrue(TCollections.Equals(first.Opt_six_with_value, second.Opt_six_with_value)); |
| 562 | Assert.IsTrue(TCollections.Equals(first.Opt_seven_with_value, second.Opt_seven_with_value)); |
| 563 | Assert.IsTrue(TCollections.Equals(first.Opt_eight_with_value, second.Opt_eight_with_value)); |
| 564 | |
| 565 | Assert.AreEqual(first.Req_one_with_value, second.Req_one_with_value); |
| 566 | Assert.AreEqual(first.Req_two_with_value, second.Req_two_with_value); |
| 567 | Assert.AreEqual(first.Req_three_with_value, second.Req_three_with_value); |
| 568 | Assert.AreEqual(first.Req_four_with_value, second.Req_four_with_value); |
| 569 | Assert.IsTrue(TCollections.Equals(first.Req_five_with_value, second.Req_five_with_value)); |
| 570 | Assert.IsTrue(TCollections.Equals(first.Req_six_with_value, second.Req_six_with_value)); |
| 571 | Assert.IsTrue(TCollections.Equals(first.Req_seven_with_value, second.Req_seven_with_value)); |
| 572 | Assert.IsTrue(TCollections.Equals(first.Req_eight_with_value, second.Req_eight_with_value)); |
| 573 | |
| 574 | Assert.AreEqual(first.Def_one_with_value, second.Def_one_with_value); |
| 575 | Assert.AreEqual(first.Def_two_with_value, second.Def_two_with_value); |
| 576 | Assert.AreEqual(first.Def_three_with_value, second.Def_three_with_value); |
| 577 | Assert.AreEqual(first.Def_four_with_value, second.Def_four_with_value); |
| 578 | Assert.IsTrue(TCollections.Equals(first.Def_five_with_value, second.Def_five_with_value)); |
| 579 | Assert.IsTrue(TCollections.Equals(first.Def_six_with_value, second.Def_six_with_value)); |
| 580 | Assert.IsTrue(TCollections.Equals(first.Def_seven_with_value, second.Def_seven_with_value)); |
| 581 | Assert.IsTrue(TCollections.Equals(first.Def_eight_with_value, second.Def_eight_with_value)); |
| 582 | |
| 583 | Assert.AreEqual(first.Last_of_the_mohicans, second.Last_of_the_mohicans); |
| 584 | |
| 585 | Assert.IsTrue(TCollections.Equals(first.Far_list, second.Far_list)); |
| 586 | Assert.IsTrue(TCollections.Equals(first.Far_set, second.Far_set)); |
| 587 | Assert.IsTrue(TCollections.Equals(first.Far_map, second.Far_map)); |
| 588 | |
| 589 | Assert.IsTrue(TCollections.Equals(first.Far_set_list, second.Far_set_list)); |
| 590 | Assert.IsTrue(TCollections.Equals(first.Far_list_map_set, second.Far_list_map_set)); |
| 591 | Assert.IsTrue(TCollections.Equals(first.Far_map_dist_to_rds, second.Far_map_dist_to_rds)); |
| 592 | |
| 593 | Assert.AreEqual(first.Req_nested, second.Req_nested); |
| 594 | Assert.AreEqual(first.Opt_nested, second.Opt_nested); |
| 595 | Assert.AreEqual(first.Def_nested, second.Def_nested); |
| 596 | |
| 597 | Assert.AreEqual(first.Req_union, second.Req_union); |
| 598 | Assert.AreEqual(first.Opt_union, second.Opt_union); |
| 599 | Assert.AreEqual(first.Def_union, second.Def_union); |
| 600 | |
| 601 | Assert.AreEqual(first.Triplesix, second.Triplesix); |
| 602 | } |
| 603 | |
| 604 | } |
| 605 | } |