Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add FIO #29

Open
wants to merge 4 commits into
base: Vitalina_Kazaeva
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CourseApp.Tests/CourseApp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<NoWarn>1573,1591,1701;1702;1705</NoWarn>
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
24 changes: 17 additions & 7 deletions CourseApp.Tests/Module2/BubbleSortTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@ namespace CourseApp.Tests.Module2
[Collection("Sequential")]
public class BubbleSortTest : IDisposable
{
private const string Inp1 = @"7
5 1 7 3 9 4 1";
private const string Inp1 = @"4
4 3 2 1";

private const string Inp2 = @"3
-10 7 2";
private const string Out1 = @"3 4 2 1
3 2 4 1
3 2 1 4
2 3 1 4
2 1 3 4
1 2 3 4";
private const string Inp2 = @"4
1 2 3 4";

private const string Out2 = @"0";

public void Dispose()
{
Expand All @@ -24,8 +32,9 @@ public void Dispose()
}

[Theory]
[InlineData(Inp1, "1 1 3 4 5 7 9")]
[InlineData(Inp2, "-10 2 7")]
[InlineData(Inp1, Out1)]
[InlineData(Inp2, Out2)]

public void Test1(string input, string expected)
{
var stringWriter = new StringWriter();
Expand All @@ -39,7 +48,8 @@ public void Test1(string input, string expected)

// assert
var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
Assert.Equal($"{expected}", output[0]);
var result = string.Join(Environment.NewLine, output);
Assert.Equal($"{expected}", result);
}
}
}
86 changes: 86 additions & 0 deletions CourseApp.Tests/Module2/MergeSortTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.IO;
using Xunit;
using CourseApp.Module2;

namespace CourseApp.Tests.Module2
{
[Collection("Sequential")]
public class MergeSortTest : IDisposable
{
private const string Inp1 = @"4
4 3 2 1";

private const string Out1 = @"3 4 2 1
3 2 4 1
3 2 1 4
2 3 1 4
2 1 3 4
1 2 3 4";
private const string Inp2 = @"4
1 2 3 4";

private const string Out2 = @"0";

public void Dispose()
{
var standardOut = new StreamWriter(Console.OpenStandardOutput());
standardOut.AutoFlush = true;
var standardIn = new StreamReader(Console.OpenStandardInput());
Console.SetOut(standardOut);
Console.SetIn(standardIn);
}

[Theory]
[InlineData(new int[] { 1 }, new int[] { 2 }, new int[] { 1 , 2 })]
[InlineData(new int[] { 1 }, new int[] { 2, 3 }, new int[] { 1, 2, 3 })]
[InlineData(new int[] { 5, 6 }, new int[] { 2 }, new int[] { 2, 5, 6 })]
[InlineData(new int[] { 1, 3}, new int[] { 3, 4 }, new int[] { 1, 3, 3, 4 })]
public void TestMerge(int[] a, int[] b, int[] exp)
{
var res = MergeSort.Merge(a, b);
Assert.Equal(exp, res);
}

[Theory]
[InlineData(new int[] { 4, 3, 2, 1 }, new int[] { 4, 3 }, new int[] { 2, 1 })]
[InlineData(new int[] { 5, 4, 3, 2, 1 }, new int[] { 5, 4 }, new int[] { 3, 2, 1 })]
public void TestSplit(int[] array, int[] leftExp, int[] rightExp)
{
var (left, right) = MergeSort.Split(array);
Assert.Equal(leftExp, left);
Assert.Equal(rightExp, right);
}

[Theory]
[InlineData(new int[] { 4, 3, 2, 1 }, new int[] { 1, 2, 3, 4 })]
[InlineData(new int[] { 5, 4, 3, 2, 1 }, new int[] { 1, 2, 3, 4, 5 })]
public void TestSorting(int[] array, int[] expResult)
{
var result = MergeSort.MergeSorting(array);
Assert.Equal(expResult, result);
}

/*[Theory]
[InlineData(Inp1, Out1)]
[InlineData(Inp2, Out2)]

public void Test1(string input, string expected)
{
var stringWriter = new StringWriter();
Console.SetOut(stringWriter);

var stringReader = new StringReader(input);
Console.SetIn(stringReader);

// act
BubbleSort.BubbleSortMethod();

// assert
var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
var result = string.Join(Environment.NewLine, output);
Assert.Equal($"{expected}", result);
}
*/
}
}
59 changes: 59 additions & 0 deletions CourseApp.Tests/Module2/PairSortTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.IO;
using Xunit;
using CourseApp.Module2;

namespace CourseApp.Tests.Module2
{
[Collection("Sequential")]
public class PairSortTest : IDisposable
{
private const string Inp1 = @"3
101 80
305 90
200 14";

private const string Out1 = @"305 90
101 80
200 14";

private const string Inp2 = @"3
20 80
30 90
25 90";

private const string Out2 = @"25 90
30 90
20 80";

public void Dispose()
{
var standardOut = new StreamWriter(Console.OpenStandardOutput());
standardOut.AutoFlush = true;
var standardIn = new StreamReader(Console.OpenStandardInput());
Console.SetOut(standardOut);
Console.SetIn(standardIn);
}

[Theory]
[InlineData(Inp1, Out1)]
[InlineData(Inp2, Out2)]

public void Test1(string input, string expected)
{
var stringWriter = new StringWriter();
Console.SetOut(stringWriter);

var stringReader = new StringReader(input);
Console.SetIn(stringReader);

// act
PairSort.PairSortMethod();

// assert
var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
var result = string.Join(Environment.NewLine, output);
Assert.Equal($"{expected}", result);
}
}
}
93 changes: 93 additions & 0 deletions CourseApp.Tests/Module2/RadixSortTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.IO;
using Xunit;
using CourseApp.Module2;

namespace CourseApp.Tests.Module2
{
[Collection("Sequential")]
public class RadixSortTest : IDisposable
{
private const string Inp1 = @"9
12
32
45
67
98
29
61
35
09";

private const string Out1 = @"Initial array:
12, 32, 45, 67, 98, 29, 61, 35, 09
**********
Phase 1
Bucket 0: empty
Bucket 1: 61
Bucket 2: 12, 32
Bucket 3: empty
Bucket 4: empty
Bucket 5: 45, 35
Bucket 6: empty
Bucket 7: 67
Bucket 8: 98
Bucket 9: 29, 09
**********
Phase 2
Bucket 0: 09
Bucket 1: 12
Bucket 2: 29
Bucket 3: 32, 35
Bucket 4: 45
Bucket 5: empty
Bucket 6: 61, 67
Bucket 7: empty
Bucket 8: empty
Bucket 9: 98
**********
Sorted array:
09, 12, 29, 32, 35, 45, 61, 67, 98";

public void Dispose()
{
var standardOut = new StreamWriter(Console.OpenStandardOutput());
standardOut.AutoFlush = true;
var standardIn = new StreamReader(Console.OpenStandardInput());
Console.SetOut(standardOut);
Console.SetIn(standardIn);
}

/*[Theory]
[InlineData(new int[] { 1 }, new int[] { 2 }, new int[] { 1, 2 })]
[InlineData(new int[] { 1 }, new int[] { 2, 3 }, new int[] { 1, 2, 3 })]
[InlineData(new int[] { 5, 6 }, new int[] { 2 }, new int[] { 2, 5, 6 })]
[InlineData(new int[] { 1, 3 }, new int[] { 3, 4 }, new int[] { 1, 3, 3, 4 })]
public void TestMerge(int[] a, int[] b, int[] exp)
{
var res = MergeSort.Merge(a, b);
Assert.Equal(exp, res);
}
*/
[Theory]
[InlineData(Inp1, Out1)]

public void Test1(string input, string expected)
{
var stringWriter = new StringWriter();
Console.SetOut(stringWriter);

var stringReader = new StringReader(input);
Console.SetIn(stringReader);

// act
RadixSort.Main();

// assert
var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
var result = string.Join(Environment.NewLine, output);
Assert.Equal($"{expected}", result);
}

}
}
74 changes: 74 additions & 0 deletions CourseApp.Tests/Module3/RabinCarpTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.IO;
using Xunit;
using CourseApp.Module3;

namespace CourseApp.Tests.Module3
{
using System;
using System.Collections.Generic;
using System.IO;
using Xunit;
using CourseApp.Module3;

[Collection("Sequential")]
public class RabinCarpTest : IDisposable
{
private const string Inp1 = @"ababbababa
aba
";

private const string Out1 = @"0 5 7";

public void Dispose()
{
var standardOut = new StreamWriter(Console.OpenStandardOutput());
standardOut.AutoFlush = true;
var standardIn = new StreamReader(Console.OpenStandardInput());
Console.SetOut(standardOut);
Console.SetIn(standardIn);
}

[Theory]
//[InlineData("AB", 3, 7, 1)]
[InlineData("BBA", 3, 7, 4)]
//[InlineData("ABBA", 3, 7, 5)]
//[InlineData("aba", 257, 3571, 907)]

public void TestHash1(string input, int x, int p, int exp)
{
var res = RabinCarp.CalculateHash(input, x, p);
Assert.Equal(exp, res);
}

[Theory]
[InlineData("ABB", 'A', 4, 3, 7, 5)]
[InlineData("aba", 'b', 907, 257, 3571, 2422)]

public void TestSlidingHash1(string input, char append, int hash, int x, int p, int exp)
{
var res = RabinCarp.SlidingHash(input, append, hash, x, p);
Assert.Equal(exp, res);
}

[Theory]
[InlineData(Inp1, Out1)]

public void Test1(string input, string expected)
{
var stringWriter = new StringWriter();
Console.SetOut(stringWriter);

var stringReader = new StringReader(input);
Console.SetIn(stringReader);

// act
RabinCarp.RabinCarpMethod();

// assert
var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries);
var result = string.Join(Environment.NewLine, output);
Assert.Equal($"{expected}", result);
}
}
}
2 changes: 1 addition & 1 deletion CourseApp/CourseApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<NoWarn>1573,1591,1701;1702;1705;</NoWarn>
</PropertyGroup>

Expand Down
Loading