Commit f0b21708 authored by hasan  khaddour's avatar hasan khaddour

Add Lab 4 code , Unit test lab

parent 4bea7b21
using System;
namespace Dummy.Console
{
public class DegreeConverter
{
public double ToFahrenheit(double celicius)
{
return ((celicius * 9) / 5) + 32;
}
public double ToCelicius(double fahrenheit)
{
return (32 * fahrenheit - 32) * 5 / 9;
}
public double devide(double x, double y)
{
if (y == 0)
{
throw new ArithmeticException("can't devide on 0");
}
return x / y;
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dummy.Console
{
public class MyStack<T>
{
private readonly List<T> _list = new List<T>();
public bool IsEmpty => Count == 0;
public int Count => _list.Count;
public void Push(T value)
{
_list.Add(value);
}
public void Pop()
{
if (IsEmpty)
throw new InvalidOperationException();
_list.RemoveAt(Count - 1);
}
public T Peek()
{
return _list[Count - 1];
}
}
}
using System;
namespace Dummy.Console
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
namespace Dummy.Quiz
{
public class FizzzBuzz
{
public string Buzz(int input)
{
if(input % 5== 0 && input % 3 ==0)
{
return "FizzBuzzz";
}else
if (input % 5 == 0)
{
return "Buzzz";
}
if (input % 3 == 0)
{
return "Fizz";
}
return "";
}
}
}
using System;
namespace Dummy.Quiz
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="coverlet.collector" Version="3.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Dummy.Quiz\Dummy.Quiz.csproj" />
</ItemGroup>
</Project>
using Dummy.Quiz;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dummy.QuizTests
{
public class FizzBuzzTests
{
private FizzzBuzz _fizzzBuzz;
[SetUp]
public void Setup()
{
_fizzzBuzz = new FizzzBuzz();
}
[TestCase(15,"FizzBuzz")]
[TestCase(30, "FizzBuzz")]
[TestCase(25, "Buzz")]
[TestCase(5, "Buzz")]
[TestCase(3, "Fizz")]
[TestCase(9, "Fizz")]
[TestCase(18, "Fizz")]
[TestCase(7, "")]
public void Test_Fizz_Fizzz_orFizBuzz(int input,string predicted)
{
string reult = _fizzzBuzz.Buzz(input);
Assert.AreEqual(reult,predicted);
}
}
}
using Dummy.Console;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dummy.Tests
{
[TestFixture]
public class DegreeConverterTests
{
private DegreeConverter _degreeConverter;
[SetUp]
public void SetUp()
{
_degreeConverter = new DegreeConverter();
}
[TestCase(0,32)]
[TestCase(5, 41)]
[TestCase(10, 50)]
public void ToFahrenheit_celicusDegree_returnCorrectValue(double celcuisDegree , double expectedValue)
{
// Act
double actual = _degreeConverter.ToFahrenheit(celcuisDegree);
// Fact
Assert.AreEqual(expectedValue , actual);
}
[Test]
public void ToFahrenheit_passZero_32()
{
// Arrange
double expected = 32;
double testValue = 0;
// Act
double actual = _degreeConverter.ToFahrenheit(testValue);
// Fact
Assert.AreEqual(expected, actual);
}
[Test]
[TestCase(5,0)]
[TestCase(52, 0)]
[TestCase(15, 0)]
public void deivde_tozero_throwsArithmeticException(double nominator , double denominator)
{
//Assert
Assert.Throws<ArithmeticException>(() => _degreeConverter.devide(nominator, denominator));
}
[TestCase(10, 2,5)]
[TestCase(60, 30,2)]
[TestCase(30, 15,2)]
public void deivde_tononZero_returnExpectedResult(double nominator, double denominator, double actual)
{
double result = _degreeConverter.devide(nominator, denominator);
//Assert
Assert.AreEqual(result,actual);
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="coverlet.collector" Version="3.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Dummy.Console\Dummy.Console.csproj" />
</ItemGroup>
</Project>
......@@ -5,12 +5,22 @@ VisualStudioVersion = 16.0.34601.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dummy.SeleniumTests", "test\Dummy.SeleniumTests\Dummy.SeleniumTests.csproj", "{D4453780-BA9F-4FAE-9A40-A2878D4DA2FF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dummy.WebApp", "src\Dummy.WebApp\Dummy.WebApp.csproj", "{D2813A54-8E25-4717-BA9A-1136841CFC70}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source Code", "Source Code", "{C7744431-99CC-4DC4-8B9E-4C8990080EDC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{8DFC9025-3CCF-4C18-9DE2-FF1A01FF92AC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dummy.Console", "Dummy.Console\Dummy.Console.csproj", "{C91E3E65-EE84-428E-896A-D13471421D86}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dummy.Tests", "Dummy.Tests\Dummy.Tests.csproj", "{C4411D66-98F2-49A5-A9AC-633F0C0D6F7B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dummy.Quiz", "Dummy.Quiz\Dummy.Quiz.csproj", "{F1D1139D-B330-4EF4-9058-74F78E4B3BFB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dummy.QuizTests", "Dummy.QuizTests\Dummy.QuizTests.csproj", "{FB6A26F2-EF13-44C7-A6AC-A48CC0DF9BAF}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Console", "Console", "{A58F1660-1E98-4B48-ADFF-DABC4E24616C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Quiz", "Quiz", "{639DD7FA-D40D-49E7-9608-7193BE6497BF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -21,17 +31,34 @@ Global
{D4453780-BA9F-4FAE-9A40-A2878D4DA2FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4453780-BA9F-4FAE-9A40-A2878D4DA2FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4453780-BA9F-4FAE-9A40-A2878D4DA2FF}.Release|Any CPU.Build.0 = Release|Any CPU
{D2813A54-8E25-4717-BA9A-1136841CFC70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D2813A54-8E25-4717-BA9A-1136841CFC70}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D2813A54-8E25-4717-BA9A-1136841CFC70}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D2813A54-8E25-4717-BA9A-1136841CFC70}.Release|Any CPU.Build.0 = Release|Any CPU
{C91E3E65-EE84-428E-896A-D13471421D86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C91E3E65-EE84-428E-896A-D13471421D86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C91E3E65-EE84-428E-896A-D13471421D86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C91E3E65-EE84-428E-896A-D13471421D86}.Release|Any CPU.Build.0 = Release|Any CPU
{C4411D66-98F2-49A5-A9AC-633F0C0D6F7B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C4411D66-98F2-49A5-A9AC-633F0C0D6F7B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4411D66-98F2-49A5-A9AC-633F0C0D6F7B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4411D66-98F2-49A5-A9AC-633F0C0D6F7B}.Release|Any CPU.Build.0 = Release|Any CPU
{F1D1139D-B330-4EF4-9058-74F78E4B3BFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F1D1139D-B330-4EF4-9058-74F78E4B3BFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1D1139D-B330-4EF4-9058-74F78E4B3BFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F1D1139D-B330-4EF4-9058-74F78E4B3BFB}.Release|Any CPU.Build.0 = Release|Any CPU
{FB6A26F2-EF13-44C7-A6AC-A48CC0DF9BAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB6A26F2-EF13-44C7-A6AC-A48CC0DF9BAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB6A26F2-EF13-44C7-A6AC-A48CC0DF9BAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB6A26F2-EF13-44C7-A6AC-A48CC0DF9BAF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D4453780-BA9F-4FAE-9A40-A2878D4DA2FF} = {8DFC9025-3CCF-4C18-9DE2-FF1A01FF92AC}
{D2813A54-8E25-4717-BA9A-1136841CFC70} = {C7744431-99CC-4DC4-8B9E-4C8990080EDC}
{C91E3E65-EE84-428E-896A-D13471421D86} = {A58F1660-1E98-4B48-ADFF-DABC4E24616C}
{C4411D66-98F2-49A5-A9AC-633F0C0D6F7B} = {8DFC9025-3CCF-4C18-9DE2-FF1A01FF92AC}
{F1D1139D-B330-4EF4-9058-74F78E4B3BFB} = {639DD7FA-D40D-49E7-9608-7193BE6497BF}
{FB6A26F2-EF13-44C7-A6AC-A48CC0DF9BAF} = {8DFC9025-3CCF-4C18-9DE2-FF1A01FF92AC}
{A58F1660-1E98-4B48-ADFF-DABC4E24616C} = {C7744431-99CC-4DC4-8B9E-4C8990080EDC}
{639DD7FA-D40D-49E7-9608-7193BE6497BF} = {C7744431-99CC-4DC4-8B9E-4C8990080EDC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6022994C-495B-4C1F-8D91-893645AA30DA}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment