本文整理汇总了C#中Mathmagician.NaturalNumbers类的典型用法代码示例。如果您正苦于以下问题:C# NaturalNumbers类的具体用法?C# NaturalNumbers怎么用?C# NaturalNumbers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NaturalNumbers类属于Mathmagician命名空间,在下文中一共展示了NaturalNumbers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldPrintFirstNumber
public void ShouldPrintFirstNumber()
{
NaturalNumbers nats = new NaturalNumbers(); //This is an instance
int expected = 1;
int actual = nats.GetFirst();
Assert.AreEqual(expected, actual);
}
示例2: ShouldPrintSequenceOfNumbers
public void ShouldPrintSequenceOfNumbers()
{
NaturalNumbers nats = new NaturalNumbers();
int[] expected = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] actual = nats.GetSequence();
CollectionAssert.AreEqual(expected, actual);
}
示例3: ShouldPrintFirstNumber
public void ShouldPrintFirstNumber()
{
NaturalNumbers nats = new NaturalNumbers();
BigInteger expected = 1;
BigInteger actual = nats.GetFirst();
Assert.AreEqual(expected, actual);
}
示例4: Main
static void Main(string[] args)
{
string prompt = "> ";
Console.WriteLine("What do you want me to do?");
Console.Write(prompt);
string response = Console.ReadLine();
if (response == "natural numbers")
{
Console.WriteLine("How many?");
Console.Write(prompt);
string response_length = Console.ReadLine();
int length;
bool parsed = int.TryParse(response_length, out length);
if (parsed)
{
NaturalNumbers nats = new NaturalNumbers();
Console.WriteLine(nats.ToString(nats.GetSequence(length)));
}
else
{
Console.WriteLine("Whoops!");
}
}
else{
Console.WriteLine("Nope! Do better next time.");
}
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
示例5: ShouldPrintNextNumberInput3
public void ShouldPrintNextNumberInput3()
{
NaturalNumbers nats = new NaturalNumbers();
int input = 3;
int expected = 4;
int actual = nats.GetNext(input);
Assert.AreEqual(expected, actual);
}
示例6: PrintSequenceOfNumbers
public void PrintSequenceOfNumbers()
{
NaturalNumbers nats = new NaturalNumbers();
int length = 7;
string expected = "1 2 3 4 5 6 7";
string actual = nats.ToString(nats.GetSequence(length));
Assert.AreEqual(expected, actual);
}
示例7: ShouldProvideSameSequences
public void ShouldProvideSameSequences()
{
NaturalNumbers nats = new NaturalNumbers();
int input = 10;
int[] sequenceWithLength = nats.GetSequence(input);
int[] sequenceNoLength = nats.GetSequence();
CollectionAssert.AreEqual(sequenceNoLength, sequenceWithLength);
}
示例8: ShouldPrintAVariableSequenceOfNumbers
public void ShouldPrintAVariableSequenceOfNumbers()
{
NaturalNumbers nats = new NaturalNumbers();
int input = 8;
int[] expected = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
int[] actual = nats.GetSequence(input);
CollectionAssert.AreEqual(expected, actual);
}
示例9: ShouldPrintFirstNumber
public void ShouldPrintFirstNumber()
{
NaturalNumbers nats = new NaturalNumbers();
int expected = 1;
int actual = nats.GetFirst();
//asserts can compare expected outputs vs actual outputs
Assert.AreEqual(expected, actual);
}
示例10: EnsureICanCreateClassInstance
public void EnsureICanCreateClassInstance()
{
//create a new instance of a class
NaturalNumbers nats = new NaturalNumbers();
//make sure instance is properly created
Assert.IsNotNull(nats);
//Right click on Mathagician add Class. Create new file named the class. i.e. NaturalNumbers.cs
}
示例11: ShouldPrintAVariableSequenceofNumbers
public void ShouldPrintAVariableSequenceofNumbers()
{
NaturalNumbers nats = new NaturalNumbers();
//Must create instance of the class before testing the class.
int input = 8;
int[] expected = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 };
int[] actual = nats.GetSequence(input);
CollectionAssert.AreEqual(expected, actual);
}
示例12: Main
static void Main(string[] args)
{
string prompt = "> ";
Console.WriteLine("What do you want me to do?");
Console.Write(prompt);
string response = Console.ReadLine();
if (response.ToLower().Contains("numbers"))
{
Console.WriteLine("How many?");
Console.Write(prompt);
int length;
string response_length = Console.ReadLine();
bool parsed = int.TryParse(response_length, out length);
if (parsed && Convert.ToInt32(response_length) < 1000)
{
if (response.ToLower().Equals("natural numbers"))
{
NaturalNumbers nats = new NaturalNumbers();
Console.WriteLine(nats.ToString(nats.GetSequence(length)));
}
else if (response.ToLower().Equals("even numbers"))
{
EvenNumbers even = new EvenNumbers();
Console.WriteLine(even.ToString(even.GetSequence(length)));
}
else if (response.ToLower().Equals("odd numbers"))
{
OddNumbers odd = new OddNumbers();
Console.WriteLine(odd.ToString(odd.GetSequence(length)));
}
else if (response.ToLower().Equals("fibonacci numbers"))
{
Fibonacci fib = new Fibonacci();
Console.WriteLine(fib.ToString(fib.GetSequence(length)));
}
else if (response.ToLower().Equals("prime numbers"))
{
PrimeNumbers prime = new PrimeNumbers();
Console.WriteLine(prime.ToString(prime.GetSequence(length)));
}
else
{
Console.WriteLine("Whoops!");
}
}
else {
Console.WriteLine("Whoops!");
}
}
else {
Console.WriteLine("Nope! Do better next time.");
}
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
示例13: EnsureICanCreateClassInstance
public void EnsureICanCreateClassInstance()
{
// Bootstrapping test because you have yet to create a class
// Make sure the build workflow is consistent and works well
NaturalNumbers nats = new NaturalNumbers();
// When you write tests you can ignore red squiggly lines because the class doesn't exist yet
// Every test has the form of setup then assert
Assert.IsNotNull(nats);
}
示例14: EnsureICanCreateClassInstance
public void EnsureICanCreateClassInstance()
{
NaturalNumbers nats = new NaturalNumbers(); // <---- Every test has a setup
// Assert class verifies true/false
Assert.IsNotNull(nats); // <----- And then an Assert
}
示例15: Main
static void Main(string[] args)
{
string prompt = "> ";
string splash = @" ,/ *
_,'/_ |
`("")' ,'/
_ _,-M-./ /
\_\_\. / __ __ _ _ _ _
)"" | ( | \/ | __ _| |_| |__ _ __ ___ __ _ __ _(_) ___(_) __ _ _ __
__/ M \__ | |\/| |/ _` | __| '_ \| '_ ` _ \ / _` |/ _` | |/ __| |/ _` | '_ \
\ /|\ / | | | | (_| | |_| | | | | | | | | (_| | (_| | | (__| | (_| | | | |
`--'|||`--' |_| |_|\__,_|\__|_| |_|_| |_| |_|\__,_|\__, |_|\___|_|\__,_|_| |_|
==^== |___/";
Console.WriteLine(splash);
Console.WriteLine("What do you want me to do?");
Console.Write(prompt);
string[] valid_responses = new string[] { "natural numbers", "even numbers", "odd numbers", "fibonacci numbers", "prime numbers"};
string response = Console.ReadLine().ToLower();
if (valid_responses.Contains(response))
{
Console.WriteLine("How many?");
Console.Write(prompt);
string response_length = Console.ReadLine();
int length;
bool parsed = int.TryParse(response_length, out length);
if (parsed)
{
if (response == "natural numbers")
{
NaturalNumbers nats = new NaturalNumbers();
Console.WriteLine(nats.ToString(nats.GetSequence(length)));
}
if (response == "even numbers")
{
EvenNumbers even = new EvenNumbers();
Console.WriteLine(even.ToString(even.GetSequence(length)));
}
if (response == "odd numbers")
{
OddNumbers odd = new OddNumbers();
Console.WriteLine(odd.ToString(odd.GetSequence(length)));
}
if (response == "fibonacci numbers")
{
FibonacciNumbers fibonacci = new FibonacciNumbers();
Console.WriteLine(fibonacci.ToString(fibonacci.GetSequence(length)));
}
if (response == "prime numbers")
{
PrimeNumbers prime = new PrimeNumbers();
Console.WriteLine(prime.ToString(prime.GetSequence(length)));
}
}
else
{
Console.WriteLine("Whoops!");
}
}
else
{
Console.WriteLine("Nope! Do better next time.");
}
Console.Write("Press any key to exit...");
Console.ReadKey();
}