mer unit test
This commit is contained in:
parent
8ff1f69ea3
commit
5b6d47da85
15 changed files with 386 additions and 0 deletions
22
Emne 3/Calc/Calc.sln
Normal file
22
Emne 3/Calc/Calc.sln
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Calc", "Calc\Calc.csproj", "{316D55FE-FAD0-4686-BD29-68E4B6B8DBE8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Calculator.Test", "Calculator.Test\Calculator.Test.csproj", "{57206669-909C-4445-B3B9-2444902E1C20}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{316D55FE-FAD0-4686-BD29-68E4B6B8DBE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{316D55FE-FAD0-4686-BD29-68E4B6B8DBE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{316D55FE-FAD0-4686-BD29-68E4B6B8DBE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{316D55FE-FAD0-4686-BD29-68E4B6B8DBE8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{57206669-909C-4445-B3B9-2444902E1C20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{57206669-909C-4445-B3B9-2444902E1C20}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{57206669-909C-4445-B3B9-2444902E1C20}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{57206669-909C-4445-B3B9-2444902E1C20}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
10
Emne 3/Calc/Calc/Calc.csproj
Normal file
10
Emne 3/Calc/Calc/Calc.csproj
Normal file
|
@ -0,0 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
29
Emne 3/Calc/Calc/Calculator.cs
Normal file
29
Emne 3/Calc/Calc/Calculator.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
namespace Calc;
|
||||
|
||||
public class Calculator
|
||||
{
|
||||
public int LeggSammen(int a, int b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
public int TrekkFra(int a, int b)
|
||||
{
|
||||
return a - b;
|
||||
}
|
||||
|
||||
public int Multipliser(int a, int b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
|
||||
public int Divider(int a, int b)
|
||||
{
|
||||
if (b == 0)
|
||||
{
|
||||
throw new ArgumentException("Cannot divide by zero.");
|
||||
}
|
||||
return a / b;
|
||||
}
|
||||
|
||||
}
|
3
Emne 3/Calc/Calc/Program.cs
Normal file
3
Emne 3/Calc/Calc/Program.cs
Normal file
|
@ -0,0 +1,3 @@
|
|||
// See https://aka.ms/new-console-template for more information
|
||||
|
||||
Console.WriteLine("Hello, World!");
|
28
Emne 3/Calc/Calculator.Test/Calculator.Test.csproj
Normal file
28
Emne 3/Calc/Calculator.Test/Calculator.Test.csproj
Normal file
|
@ -0,0 +1,28 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
|
||||
<PackageReference Include="NUnit" Version="3.14.0"/>
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0"/>
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Calc\Calc.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
43
Emne 3/Calc/Calculator.Test/UnitTest1.cs
Normal file
43
Emne 3/Calc/Calculator.Test/UnitTest1.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
namespace Calculator.Test;
|
||||
|
||||
public class Tests
|
||||
{
|
||||
[Test]
|
||||
public void TestLeggSammen()
|
||||
{
|
||||
var calc = new Calc.Calculator();
|
||||
var sum = calc.LeggSammen(1, 2);
|
||||
Assert.That(sum, Is.EqualTo(3));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestTrekkFra()
|
||||
{
|
||||
var calc = new Calc.Calculator();
|
||||
var sum = calc.TrekkFra(2, 1);
|
||||
Assert.That(sum, Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMultipliser()
|
||||
{
|
||||
var calc = new Calc.Calculator();
|
||||
var sum = calc.Multipliser(2, 2);
|
||||
Assert.That(sum, Is.EqualTo(4));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDivision()
|
||||
{
|
||||
var calc = new Calc.Calculator();
|
||||
var sum = calc.Divider(4, 2);
|
||||
Assert.That(sum, Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestDivisionByZero()
|
||||
{
|
||||
var calc = new Calc.Calculator();
|
||||
Assert.Throws<ArgumentException>(() => calc.Divider(4, 0));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue