mirror of
https://bitbucket.org/Mattrixwv/csclasses.git
synced 2025-12-06 18:23:58 -05:00
Added function for SieveOfEratosthenes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//C#/CSClasses/TestCSClasses/TestAlgorithms.cs
|
||||
//Matthew Ellison
|
||||
// Created: 03-11-21
|
||||
//Modified: 06-29-21
|
||||
//Modified: 06-30-21
|
||||
//This file contains the tests for the Algorithms class
|
||||
/*
|
||||
Copyright (C) 2021 Matthew Ellison
|
||||
@@ -400,5 +400,27 @@ namespace TestCSClasses{
|
||||
answer = mee.Algorithms.ToBin(bigNum);
|
||||
Assert.AreEqual(correctAnswer, answer, "ToBin big 3 failed");
|
||||
}
|
||||
[TestMethod]
|
||||
public void TestSieveOfEratosthenes(){
|
||||
//Test 1
|
||||
IEnumerator<long> sieve = mee.Algorithms.SieveOfEratosthenes().GetEnumerator();
|
||||
List<long> correctAnswer = new List<long>(){2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
|
||||
List<long> answer = new List<long>();
|
||||
for(int cnt = 0;cnt < 25;++cnt){
|
||||
sieve.MoveNext();
|
||||
answer.Add(sieve.Current);
|
||||
}
|
||||
CollectionAssert.AreEqual(correctAnswer, answer, "SieveOfEratosthenes failed");
|
||||
|
||||
//Test 2
|
||||
IEnumerator<BigInteger> bigSieve = mee.Algorithms.SieveOfEratosthenesBig().GetEnumerator();
|
||||
List<BigInteger> bigCorrectAnswer = new List<BigInteger>(){2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
|
||||
List<BigInteger> bigAnswer = new List<BigInteger>();
|
||||
for(int cnt = 0;cnt < 25;++cnt){
|
||||
bigSieve.MoveNext();
|
||||
bigAnswer.Add(bigSieve.Current);
|
||||
}
|
||||
CollectionAssert.AreEqual(bigCorrectAnswer, bigAnswer, "SieveOfEratosthenesBig failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user