ImmutableListTest.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT 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 Microsoft.VisualStudio.TestTools.UnitTesting;
  8. #endif
  9. using Assert = Xunit.Assert;
  10. namespace ReactiveTests.Tests
  11. {
  12. #if SIGNED
  13. [TestClass]
  14. public class ImmutableListTest
  15. {
  16. [TestMethod]
  17. public void ImmutableList_Basics()
  18. {
  19. var list = ImmutableList<int>.Empty;
  20. Assert.True(list.Data.SequenceEqual(new int[] { }));
  21. list = list.Add(42);
  22. Assert.True(list.Data.SequenceEqual(new int[] { 42 }));
  23. list = list.Remove(42);
  24. Assert.True(list.Data.SequenceEqual(new int[] { }));
  25. list = list.Remove(42);
  26. Assert.True(list.Data.SequenceEqual(new int[] { }));
  27. list = list.Add(43);
  28. list = list.Add(44);
  29. list = list.Add(43);
  30. Assert.True(list.Data.SequenceEqual(new int[] { 43, 44, 43 }));
  31. list = list.Remove(43);
  32. Assert.True(list.Data.SequenceEqual(new int[] { 44, 43 }));
  33. list = list.Remove(43);
  34. Assert.True(list.Data.SequenceEqual(new int[] { 44 }));
  35. list = list.Remove(44);
  36. Assert.True(list.Data.SequenceEqual(new int[] { }));
  37. }
  38. [TestMethod]
  39. public void ImmutableList_Nulls()
  40. {
  41. var list = ImmutableList<string>.Empty;
  42. Assert.True(list.Data.SequenceEqual(new string[] { }));
  43. list = list.Add(null);
  44. Assert.True(list.Data.SequenceEqual(new string[] { null }));
  45. list = list.Remove(null);
  46. Assert.True(list.Data.SequenceEqual(new string[] { }));
  47. }
  48. }
  49. #endif
  50. }