ImmutableListTest.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. using Xunit;
  5. using System.Linq;
  6. using System.Reactive;
  7. namespace ReactiveTests.Tests
  8. {
  9. #if SIGNED
  10. public class ImmutableListTest
  11. {
  12. [Fact]
  13. public void ImmutableList_Basics()
  14. {
  15. var list = ImmutableList<int>.Empty;
  16. Assert.True(list.Data.SequenceEqual(new int[] { }));
  17. list = list.Add(42);
  18. Assert.True(list.Data.SequenceEqual(new int[] { 42 }));
  19. list = list.Remove(42);
  20. Assert.True(list.Data.SequenceEqual(new int[] { }));
  21. list = list.Remove(42);
  22. Assert.True(list.Data.SequenceEqual(new int[] { }));
  23. list = list.Add(43);
  24. list = list.Add(44);
  25. list = list.Add(43);
  26. Assert.True(list.Data.SequenceEqual(new int[] { 43, 44, 43 }));
  27. list = list.Remove(43);
  28. Assert.True(list.Data.SequenceEqual(new int[] { 44, 43 }));
  29. list = list.Remove(43);
  30. Assert.True(list.Data.SequenceEqual(new int[] { 44 }));
  31. list = list.Remove(44);
  32. Assert.True(list.Data.SequenceEqual(new int[] { }));
  33. }
  34. [Fact]
  35. public void ImmutableList_Nulls()
  36. {
  37. var list = ImmutableList<string>.Empty;
  38. Assert.True(list.Data.SequenceEqual(new string[] { }));
  39. list = list.Add(null);
  40. Assert.True(list.Data.SequenceEqual(new string[] { null }));
  41. list = list.Remove(null);
  42. Assert.True(list.Data.SequenceEqual(new string[] { }));
  43. }
  44. }
  45. #endif
  46. }