Skip to content

Commit

Permalink
Added unit test, refactored the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottawo4ka authored and OzoneReloaded committed Oct 14, 2020
1 parent d603784 commit b327fd7
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 22 deletions.
22 changes: 18 additions & 4 deletions CourseApp.Tests/CourseApp.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,29 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>

<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
<NoWarn>1573,1591,1701;1702;1705</NoWarn>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.0.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CourseApp\CourseApp.csproj" />
</ItemGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>../_stylecop/stylecop.ruleset</CodeAnalysisRuleSet>
<GenerateFullPaths>true</GenerateFullPaths>
</PropertyGroup>

<ItemGroup>
<AdditionalFiles Include="../_stylecop/stylecop.json" />
</ItemGroup>

</Project>
</Project>
47 changes: 47 additions & 0 deletions CourseApp.Tests/DemoTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using Xunit;

namespace CourseApp.Tests
{
public class DemoTest
{
[Fact]
public void Test1()
{
Assert.True(true);
}

[Fact]
public void TestMyFunctionZeros()
{
var res = Program.Сalculation(0.0, 0.0, 0.0).Count;
Assert.Equal(double.NaN, res);
}

[Fact]
public void TestNullB()
{
List<double> e = new List<double>();
var res = Program.Сalculation2(e).Count;
Assert.Equal(double.NaN, res);
}

[Fact]
public void TestTrueA()
{
var res = Program.Сalculation(0.26, 0.66, 0.08);
List<double> result = new List<double>() { 0.834215045903759, 0.75429795697566, 0.688425423366074, 0.652365112574963, 0.663883187692699, 0.751251000538057 };
Assert.Equal(result, res);
}

[Fact]
public void TestTrueB()
{
List<double> input = new List<double>() { 0.1, 0.35, 0.4, 0.55, 0.6 };
var res = Program.Сalculation2(input);
List<double> result = new List<double>() { 0.970885488727385, 0.744968715506544, 0.702712806929317, 0.65257962383342, 0.677063603240845 };
Assert.Equal(res, result);
}
}
}
14 changes: 0 additions & 14 deletions CourseApp.Tests/UnitTest1.cs

This file was deleted.

16 changes: 12 additions & 4 deletions CourseApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,30 @@ public static double Mathhh(double x)
return y;
}

public static void Сalculation(double xH, double xK, double dx)
public static List<double> Сalculation(double xH, double xK, double dx)
{
int i = 0;
List<double> output = new List<double>();
for (double x = xH; x <= xK; x = x + dx)
{
Console.WriteLine("{0} ", Mathhh(x));
output.Add(Mathhh(x));
Console.WriteLine(Mathhh(x));
i++;
}

return output;
}

public static void Сalculation2(List<double> b)
public static List<double> Сalculation2(List<double> b)
{
List<double> output = new List<double>();
foreach (double i in b)
{
Console.WriteLine("{0} ", Mathhh(i));
output.Add(Mathhh(i));
Console.WriteLine(Mathhh(i));
}

return output;
}

public static void Main()
Expand Down

0 comments on commit b327fd7

Please sign in to comment.