Files

109 lines
3.2 KiB
C#

using MethodLibrary;
namespace BasicProgrammingTests;
public class LoopsTests
{
Loops loops = new Loops();
[Fact]
public void MultiplicationTable()
{
var expected = new List<List<int>>
{
new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
new List<int> { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 },
new List<int> { 3, 6, 9, 12, 15, 18, 21, 24, 27, 30 },
new List<int> { 4, 8, 12, 16, 20, 24, 28, 32, 36, 40 },
new List<int> { 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 },
new List<int> { 6, 12, 18, 24, 30, 36, 42, 48, 54, 60 },
new List<int> { 7, 14, 21, 28, 35, 42, 49, 56, 63, 70 },
new List<int> { 8, 16, 24, 32, 40, 48, 56, 64, 72, 80 },
new List<int> { 9, 18, 27, 36, 45, 54, 63, 72, 81, 90 },
new List<int> { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }
};
Assert.Equal(expected, loops.MultiplicationTable(10, 10));
}
[Theory]
[InlineData(291, new int[] { 190, 291, 145, 209, 280, 200 })]
[InlineData(-2, new int[] { -9, -2, -7, -8, -4 })]
public void TheBiggestNumber(int expected, int[] a)
{
Assert.Equal(expected, loops.TheBiggestNumber(a.ToList()));
}
[Theory]
[InlineData(1, new int[] { 8, 2, 5, 7, 9, 0, 7, 7, 3, 1 })]
[InlineData(3, new int[] { 9, 4, 5, 3, 7, 7, 7, 3, 2, 5, 7, 7 })]
public void Two7sNextToEachOther(int expected, int[] a)
{
Assert.Equal(expected, loops.Two7sNextToEachOther(a.ToList()));
}
[Theory]
[InlineData(true, new int[] { 45, 23, 44, 68, 65, 70, 80, 81, 82 })]
[InlineData(false, new int[] { 7, 3, 5, 8, 9, 3, 1, 4 })]
public void ThreeIncreasingAdjacent(bool expected, int[] a)
{
Assert.Equal(expected, loops.ThreeIncreasingAdjacent(a.ToList()));
}
[Theory]
[InlineData(new int[] {2, 3, 5, 7, 11, 13, 17, 19, 23, 29}, 30)]
public void SieveOfEratosthenes(int[] expected, int a)
{
Assert.Equal(expected.ToList(), loops.SieveOfEratosthenes(a));
}
[Theory]
[InlineData("abc", "##abc##def")]
[InlineData("", "12####78")]
[InlineData("", "gar##d#en")]
[InlineData("--", "++##--##++")]
public void ExtractString(string expected, string a)
{
Assert.Equal(expected, loops.ExtractString(a));
}
[Theory]
[InlineData("defghijklmnopqrs", "ds")]
[InlineData("opqr", "or")]
public void FullSequenceOfLetters(string expected, string a)
{
Assert.Equal(expected, loops.FullSequenceOfLetters(a));
}
[Theory]
[InlineData("Sum: 2156, Average: 38,5", 11, 66)]
[InlineData("Sum: -55, Average: -5", -10, 0)]
public void SumAndAverage(string expected, int a, int b)
{
Assert.Equal(expected, loops.SumAndAverage(a, b));
}
[Fact]
public void DrawTriangle()
{
Assert.Equal(
@" *
***
*****
*******
*********
***********
*************
***************
*****************
*******************", loops.DrawTriangle(10));
}
[Theory]
[InlineData(-8, -2, 3)]
[InlineData(3125, 5, 5)]
public void ToThePowerOf(int expected, int a, int b)
{
Assert.Equal(expected, loops.ToThePowerOf(a, b));
}
}