Compare commits
2 Commits
d57d317d0b
...
c156c70b78
| Author | SHA1 | Date | |
|---|---|---|---|
| c156c70b78 | |||
| 54aeba226d |
@@ -1,8 +1,10 @@
|
|||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.5.2.0
|
VisualStudioVersion = 17.5.2.0
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicProgramming", "BasicProgramming.csproj", "{F852DB4D-952E-CFAF-DFC6-298FB48C8A28}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicProgramming", "BasicProgramming\BasicProgramming.csproj", "{F852DB4D-952E-CFAF-DFC6-298FB48C8A28}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicProgrammingUnitTest", "BasicProgrammingUnitTest\BasicProgrammingUnitTest.csproj", "{427B1690-1D9B-4002-A6DE-435867230BAC}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -14,6 +16,10 @@ Global
|
|||||||
{F852DB4D-952E-CFAF-DFC6-298FB48C8A28}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{F852DB4D-952E-CFAF-DFC6-298FB48C8A28}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{F852DB4D-952E-CFAF-DFC6-298FB48C8A28}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{F852DB4D-952E-CFAF-DFC6-298FB48C8A28}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{F852DB4D-952E-CFAF-DFC6-298FB48C8A28}.Release|Any CPU.Build.0 = Release|Any CPU
|
{F852DB4D-952E-CFAF-DFC6-298FB48C8A28}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{427B1690-1D9B-4002-A6DE-435867230BAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{427B1690-1D9B-4002-A6DE-435867230BAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{427B1690-1D9B-4002-A6DE-435867230BAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{427B1690-1D9B-4002-A6DE-435867230BAC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace BasicProgramming
|
namespace BasicProgramming
|
||||||
{
|
{
|
||||||
internal class Program
|
public class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
@@ -41,12 +41,12 @@ namespace BasicProgramming
|
|||||||
Console.WriteLine($"IfYearIsLeap(2018): {IfYearIsLeap(2018)}");
|
Console.WriteLine($"IfYearIsLeap(2018): {IfYearIsLeap(2018)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int AddAndMultiply(int a, int b, int c)
|
public static int AddAndMultiply(int a, int b, int c)
|
||||||
{
|
{
|
||||||
return (a + b) * c;
|
return (a + b) * c;
|
||||||
}
|
}
|
||||||
|
|
||||||
static string CtoF(int celcius)
|
public static string CtoF(int celcius)
|
||||||
{
|
{
|
||||||
if (celcius <= -271.15)
|
if (celcius <= -271.15)
|
||||||
return "Temperature below absolute zero!";
|
return "Temperature below absolute zero!";
|
||||||
@@ -56,7 +56,7 @@ namespace BasicProgramming
|
|||||||
return $"T = {fahrenheit}F";
|
return $"T = {fahrenheit}F";
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<double> ElementaryOperations(double a, double b)
|
public static List<double> ElementaryOperations(double a, double b)
|
||||||
{
|
{
|
||||||
List<double> retval = [a + b, a - b, a * b];
|
List<double> retval = [a + b, a - b, a * b];
|
||||||
if (a > 0 && b > 0)
|
if (a > 0 && b > 0)
|
||||||
@@ -65,32 +65,32 @@ namespace BasicProgramming
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IsResultTheSame(double a, double b)
|
public static bool IsResultTheSame(double a, double b)
|
||||||
{
|
{
|
||||||
return a == b;
|
return a == b;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ModuloOperations(int a, int b, int c)
|
public static int ModuloOperations(int a, int b, int c)
|
||||||
{
|
{
|
||||||
return (a % b) % c;
|
return (a % b) % c;
|
||||||
}
|
}
|
||||||
|
|
||||||
static double CubeOf(double a)
|
public static double CubeOf(double a)
|
||||||
{
|
{
|
||||||
return a * a * a;
|
return a * a * a;
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<int> SwapTwoNumbers(int a, int b)
|
public static List<int> SwapTwoNumbers(int a, int b)
|
||||||
{
|
{
|
||||||
return [b, a];
|
return [b, a];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int AbsoluteValue(int a)
|
public static int AbsoluteValue(int a)
|
||||||
{
|
{
|
||||||
return Math.Abs(a);
|
return Math.Abs(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DivisibleBy2Or3(int a, int b)
|
public static int DivisibleBy2Or3(int a, int b)
|
||||||
{
|
{
|
||||||
if (_DivisibleBy2Or3(a) && _DivisibleBy2Or3(b))
|
if (_DivisibleBy2Or3(a) && _DivisibleBy2Or3(b))
|
||||||
{
|
{
|
||||||
@@ -106,12 +106,12 @@ namespace BasicProgramming
|
|||||||
return a + b;
|
return a + b;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IfConsistsOfUppercaseLetters(string str)
|
public static bool IfConsistsOfUppercaseLetters(string str)
|
||||||
{
|
{
|
||||||
return str.Equals(Regex.Match(str, "[A-ZÆØÅ]+").Value);
|
return str.Equals(Regex.Match(str, "[A-ZÆØÅ]+").Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IfGreaterThanThirdOne(List<int> ints)
|
public static bool IfGreaterThanThirdOne(List<int> ints)
|
||||||
{
|
{
|
||||||
if (ints.Count < 3)
|
if (ints.Count < 3)
|
||||||
{
|
{
|
||||||
@@ -121,12 +121,12 @@ namespace BasicProgramming
|
|||||||
return (ints[0] * ints[1]) > ints[2];
|
return (ints[0] * ints[1]) > ints[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IfNumberIsEven(int a)
|
public static bool IfNumberIsEven(int a)
|
||||||
{
|
{
|
||||||
return a % 2 == 0;
|
return a % 2 == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IfSortedAscending(List<int> ints)
|
public static bool IfSortedAscending(List<int> ints)
|
||||||
{
|
{
|
||||||
int lastNumber = 0;
|
int lastNumber = 0;
|
||||||
bool retval = true;
|
bool retval = true;
|
||||||
@@ -146,7 +146,7 @@ namespace BasicProgramming
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static string PositiveNegativeOrZero(double a)
|
public static string PositiveNegativeOrZero(double a)
|
||||||
{
|
{
|
||||||
switch (a)
|
switch (a)
|
||||||
{
|
{
|
||||||
@@ -159,7 +159,7 @@ namespace BasicProgramming
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IfYearIsLeap(int year)
|
public static bool IfYearIsLeap(int year)
|
||||||
{
|
{
|
||||||
return DateTime.IsLeapYear(year);
|
return DateTime.IsLeapYear(year);
|
||||||
}
|
}
|
||||||
25
BasicProgrammingUnitTest/BasicProgrammingUnitTest.csproj
Normal file
25
BasicProgrammingUnitTest/BasicProgrammingUnitTest.csproj
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||||
|
<PackageReference Include="xunit" Version="2.9.2" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="../BasicProgramming/BasicProgramming.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="Xunit" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
53
BasicProgrammingUnitTest/BasicProgramming__BASIC.cs
Normal file
53
BasicProgrammingUnitTest/BasicProgramming__BASIC.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using static BasicProgramming.Program;
|
||||||
|
|
||||||
|
namespace BasicProgrammingUnitTest;
|
||||||
|
|
||||||
|
public class BasicProgramming__BASIC
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void AddAndMultiply_TEST()
|
||||||
|
{
|
||||||
|
Assert.Equal(30, AddAndMultiply(2, 4, 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CToF_TEST()
|
||||||
|
{
|
||||||
|
Assert.Equal("T = 32F", CtoF(0));
|
||||||
|
Assert.Equal("T = 212F", CtoF(100));
|
||||||
|
Assert.Equal("Temperature below absolute zero!", CtoF(-300));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ElementaryOperations_TEST()
|
||||||
|
{
|
||||||
|
Assert.Equal([11, -5, 24, 0.375], ElementaryOperations(3, 8));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsResultTheSame_TEST()
|
||||||
|
{
|
||||||
|
Assert.True(IsResultTheSame(2 + 2, 2 * 2));
|
||||||
|
Assert.False(IsResultTheSame(9 / 3, 16 - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ModuloOperations_TEST()
|
||||||
|
{
|
||||||
|
Assert.Equal(1, ModuloOperations(8, 5, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void CubeOf_TEST()
|
||||||
|
{
|
||||||
|
Assert.Equal(8, CubeOf(2));
|
||||||
|
Assert.Equal(-166.375, CubeOf(-5.5));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void SwapTwoNumbers_TEST()
|
||||||
|
{
|
||||||
|
Assert.Equal([45, 87], SwapTwoNumbers(87, 45));
|
||||||
|
Assert.Equal([2, -13], SwapTwoNumbers(-13, 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
65
BasicProgrammingUnitTest/BasicProgramming__STATEMENTS.cs
Normal file
65
BasicProgrammingUnitTest/BasicProgramming__STATEMENTS.cs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
using static BasicProgramming.Program;
|
||||||
|
|
||||||
|
namespace BasicProgrammingUnitTest;
|
||||||
|
|
||||||
|
public class BasicProgramming__STATEMENTS
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void AbsoluteValue_TEST()
|
||||||
|
{
|
||||||
|
Assert.Equal(6832, AbsoluteValue(6832));
|
||||||
|
Assert.Equal(392, AbsoluteValue(-392));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void DivisibleBy2Or3_TEST()
|
||||||
|
{
|
||||||
|
Assert.Equal(450, DivisibleBy2Or3(15, 30));
|
||||||
|
Assert.Equal(180, DivisibleBy2Or3(2, 90));
|
||||||
|
Assert.Equal(19, DivisibleBy2Or3(7, 12));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IfConsistsOfUppercaseLetters_TEST()
|
||||||
|
{
|
||||||
|
Assert.False(IfConsistsOfUppercaseLetters("xyz"));
|
||||||
|
Assert.True(IfConsistsOfUppercaseLetters("DOG"));
|
||||||
|
Assert.False(IfConsistsOfUppercaseLetters("L9#"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IfGreaterThanThirdOne_TEST()
|
||||||
|
{
|
||||||
|
Assert.True(IfGreaterThanThirdOne([2, 7, 12]));
|
||||||
|
Assert.False(IfGreaterThanThirdOne([-5, -8, 50]));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IfNumberIsEven_TEST()
|
||||||
|
{
|
||||||
|
Assert.False(IfNumberIsEven(721));
|
||||||
|
Assert.True(IfNumberIsEven(1248));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IfSortedAscending_TEST()
|
||||||
|
{
|
||||||
|
Assert.True(IfSortedAscending([3, 7, 10]));
|
||||||
|
Assert.False(IfSortedAscending([74, 62, 99]));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void PositiveNegativeOrZero_TEST()
|
||||||
|
{
|
||||||
|
Assert.Equal("positive", PositiveNegativeOrZero(5.24));
|
||||||
|
Assert.Equal("zero", PositiveNegativeOrZero(0.0));
|
||||||
|
Assert.Equal("negative", PositiveNegativeOrZero(-994.53));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IfYearIsLeap_TEST()
|
||||||
|
{
|
||||||
|
Assert.True(IfYearIsLeap(2016));
|
||||||
|
Assert.False(IfYearIsLeap(2018));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user