ImmutableListTest.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. #if SIGNED
  5. using System.Linq;
  6. using System.Reactive;
  7. using Xunit;
  8. #endif
  9. namespace ReactiveTests.Tests
  10. {
  11. #if SIGNED
  12. public class ImmutableListTest
  13. {
  14. [Fact]
  15. public void ImmutableList_Basics()
  16. {
  17. var list = ImmutableList<int>.Empty;
  18. Assert.True(list.Data.SequenceEqual(new int[] { }));
  19. list = list.Add(42);
  20. Assert.True(list.Data.SequenceEqual(new int[] { 42 }));
  21. list = list.Remove(42);
  22. Assert.True(list.Data.SequenceEqual(new int[] { }));
  23. list = list.Remove(42);
  24. Assert.True(list.Data.SequenceEqual(new int[] { }));
  25. list = list.Add(43);
  26. list = list.Add(44);
  27. list = list.Add(43);
  28. Assert.True(list.Data.SequenceEqual(new int[] { 43, 44, 43 }));
  29. list = list.Remove(43);
  30. Assert.True(list.Data.SequenceEqual(new int[] { 44, 43 }));
  31. list = list.Remove(43);
  32. Assert.True(list.Data.SequenceEqual(new int[] { 44 }));
  33. list = list.Remove(44);
  34. Assert.True(list.Data.SequenceEqual(new int[] { }));
  35. }
  36. [Fact]
  37. public void ImmutableList_Nulls()
  38. {
  39. var list = ImmutableList<string>.Empty;
  40. Assert.True(list.Data.SequenceEqual(new string[] { }));
  41. list = list.Add(null);
  42. Assert.True(list.Data.SequenceEqual(new string[] { null }));
  43. list = list.Remove(null);
  44. Assert.True(list.Data.SequenceEqual(new string[] { }));
  45. }
  46. }
  47. #endif
  48. }