Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApp1
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- }
- }
- }
- ---------------------------
- Osztáylok
- ---------------------------
- <Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <TargetFramework>net6.0</TargetFramework>
- <ImplicitUsings>enable</ImplicitUsings>
- <Nullable>enable</Nullable>
- <IsPackable>false</IsPackable>
- </PropertyGroup>
- <ItemGroup>
- <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
- <PackageReference Include="NUnit" Version="3.13.3" />
- <PackageReference Include="NUnit3TestAdapter" Version="4.3.0" />
- <PackageReference Include="NUnit.Analyzers" Version="3.5.0" />
- <PackageReference Include="coverlet.collector" Version="3.1.2" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\ConsoleApp1\ConsoleApp1.csproj" />
- </ItemGroup>
- </Project>
- ---------------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- public class BMath
- {
- public int SumOfTwoNumbers(int x, int y)
- {
- return x + y;
- }
- public int SubtractFromX(int x, int y)
- {
- return x - y;
- }
- }
- }
- ------------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- public class PrimeTool
- {
- private int number;
- public PrimeTool(int number)
- {
- this.number = number;
- }
- public bool IsPrime()
- {
- if (this.number == 1) return false;
- if (this.number == 2) return true;
- for (int i = 2; i <= Math.Ceiling(Math.Sqrt(number)); ++i)
- {
- if (number % i == 0)
- {
- return false;
- }
- }
- return true;
- }
- }
- }
- -------------------------------------------
- using ConsoleApp1;
- using NUnit.Framework;
- namespace TestProject1
- {
- public class Tests
- {
- [TestCase(3, 3)]
- [TestCase(2, 2)]
- [TestCase(1, 1)]
- public void TestSumOfNumbers(int x, int y)
- {
- BMath bMath = new BMath();
- Assert.AreEqual(x + y, bMath.SumOfTwoNumbers(x, y));
- }
- [TestCase(3, 3)]
- [TestCase(2, 2)]
- [TestCase(1, 1)]
- public void TestSubtractFromX(int x, int y)
- {
- BMath bMath = new BMath();
- Assert.AreEqual(x - y, bMath.SubtractFromX(x, y));
- }
- [TestCase(3, true)]
- [TestCase(2, true)]
- [TestCase(1, false)]
- [TestCase(9, false)]
- [TestCase(17, true)]
- public void TestIsPrime(int number, bool expectedResults)
- {
- PrimeTool primeTool = new PrimeTool(number);
- Assert.AreEqual(expectedResults, primeTool.IsPrime());
- }
- [TestCase(3)]
- [TestCase(2)]
- [TestCase(17)]
- public void TestIsPrimeTrue(int number)
- {
- PrimeTool primeTool = new PrimeTool(number);
- Assert.True(primeTool.IsPrime());
- }
- [TestCase(1)]
- [TestCase(9)]
- [TestCase(4)]
- public void TestIsPrimeFalse(int number)
- {
- PrimeTool primeTool = new PrimeTool(number);
- Assert.False(primeTool.IsPrime());
- }
- [TestCase(new int[] {2, 3, 5}, 10)]
- [TestCase(new int[] {2, 2, 2}, 6)]
- [TestCase(new int[] {1, 3, 4}, 8)]
- [TestCase(new int[] {5, 5, 5}, 15)]
- [TestCase(new int[] {0, 1, 6}, 7)]
- public void TestTotal(int[] numbers, int expectedResults)
- {
- ArrayStatistics arrayStatistics = new ArrayStatistics(numbers);
- Assert.AreEqual(expectedResults, arrayStatistics.Total());
- }
- }
- }
- ----------------------------------------
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- public class ArrayStatistics
- {
- private int[] array;
- public ArrayStatistics(int[] array)
- {
- this.array = array;
- }
- public int Total()
- {
- int sum = 0;
- for (int i = 0; i < array.Length; i++)
- {
- sum += array[i];
- }
- return sum;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement