Skip to content

Commit

Permalink
Merge pull request #134 from RyanGrange/issue129
Browse files Browse the repository at this point in the history
Issue 129: Return primes list as read-only.
  • Loading branch information
aalhour authored May 27, 2020
2 parents 897712d + e97c2cf commit ad09171
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions DataStructures/Common/PrimesList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ public int GetPreviousPrime(int number)
}

/// <summary>
/// Returns the list of primes
/// Returns the read-only IList of primes
/// </summary>
public List<int> GetAll
public IList<int> GetAll
{
get { return _primes; }
get { return _primes.AsReadOnly(); }
}

/// <summary>
Expand Down
11 changes: 10 additions & 1 deletion UnitTest/DataStructuresTests/PrimeListTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DataStructures.Common;
using System;
using DataStructures.Common;
using Xunit;

namespace UnitTest.DataStructuresTests
Expand All @@ -11,5 +12,13 @@ public void DoTest()
var instance = PrimesList.Instance;
Assert.Equal(10000, instance.Count);
}

[Fact]
public void PrimesListIsReadOnly()
{
var instance = PrimesList.Instance;
NotSupportedException ex = Assert.Throws<NotSupportedException>(() => instance.GetAll[0] = -1);
Assert.Equal("Collection is read-only.", ex.Message);
}
}
}

0 comments on commit ad09171

Please sign in to comment.