Skip to content

Commit 5bea292

Browse files
committed
Add unit tests
1 parent ab7009d commit 5bea292

File tree

5 files changed

+150
-0
lines changed

5 files changed

+150
-0
lines changed

Minecraft Enchantment Cracker.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.28307.1062
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Minecraft Enchantment Cracker", "Minecraft Enchantment Cracker\Minecraft Enchantment Cracker.csproj", "{DEF0A159-01DC-4467-8CB0-45533335C177}"
77
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{A10F28EF-0CFC-48A7-B735-B32B4A103C50}"
9+
EndProject
810
Global
911
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1012
Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
1517
{DEF0A159-01DC-4467-8CB0-45533335C177}.Debug|Any CPU.Build.0 = Debug|Any CPU
1618
{DEF0A159-01DC-4467-8CB0-45533335C177}.Release|Any CPU.ActiveCfg = Release|Any CPU
1719
{DEF0A159-01DC-4467-8CB0-45533335C177}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{A10F28EF-0CFC-48A7-B735-B32B4A103C50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{A10F28EF-0CFC-48A7-B735-B32B4A103C50}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{A10F28EF-0CFC-48A7-B735-B32B4A103C50}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{A10F28EF-0CFC-48A7-B735-B32B4A103C50}.Release|Any CPU.Build.0 = Release|Any CPU
1824
EndGlobalSection
1925
GlobalSection(SolutionProperties) = preSolution
2026
HideSolutionNode = FALSE

Tests/Properties/AssemblyInfo.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
// General Information about an assembly is controlled through the following
5+
// set of attributes. Change these attribute values to modify the information
6+
// associated with an assembly.
7+
[assembly: AssemblyTitle("Tests")]
8+
[assembly: AssemblyDescription("")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyCompany("")]
11+
[assembly: AssemblyProduct("Tests")]
12+
[assembly: AssemblyCopyright("Copyright © 2020")]
13+
[assembly: AssemblyTrademark("")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// Setting ComVisible to false makes the types in this assembly not visible
17+
// to COM components. If you need to access a type in this assembly from
18+
// COM, set the ComVisible attribute to true on that type.
19+
[assembly: ComVisible(false)]
20+
21+
// The following GUID is for the ID of the typelib if this project is exposed to COM
22+
[assembly: Guid("A10F28EF-0CFC-48A7-B735-B32B4A103C50")]
23+
24+
// Version information for an assembly consists of the following four values:
25+
//
26+
// Major Version
27+
// Minor Version
28+
// Build Number
29+
// Revision
30+
//
31+
// You can specify all the values or you can default the Build and Revision Numbers
32+
// by using the '*' as shown below:
33+
// [assembly: AssemblyVersion("1.0.*")]
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]

Tests/Tests.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Minecraft_Enchantment_Cracker.Tasks;
2+
using NUnit.Framework;
3+
4+
namespace Tests
5+
{
6+
[TestFixture]
7+
public class RngTests
8+
{
9+
/// <summary>
10+
/// This method tests that the output of GetSeed returns a seed consistent
11+
/// with the constructor Random(long seed) or SetSeed
12+
/// </summary>
13+
[Test]
14+
public static void GetSeed_Tests()
15+
{
16+
const int inputSeed = 1337;
17+
var output = JavaRandom.GetSeed(inputSeed);
18+
const long expectedOutput = 25214903124;
19+
Assert.AreEqual(output, expectedOutput);
20+
}
21+
22+
/// <summary>
23+
/// This method tests the output of the NextInt method to ensure that it
24+
/// successfully changes the seed and outputs the correct value
25+
/// </summary>
26+
/// <param name="seed">The input seed to the PRNG</param>
27+
/// <param name="max">The maximum value passed to NextInt (exclusive)</param>
28+
/// <param name="expectedSeed">The expected seed after one iteration of the PRNG</param>
29+
/// <param name="expectedVal">The expected output of the NextInt call</param>
30+
[TestCase(1337L, 420, 33712326537040L, 419)]
31+
[TestCase(123456789L, 8, 119305093197820L, 3)]
32+
[TestCase(999999999L, 1, 94003067820958L, 0)]
33+
public static void NextInt_Tests(ref long seed, ref int max, long expectedSeed, int expectedVal)
34+
{
35+
var result = seed.NextInt(max);
36+
Assert.AreEqual(expectedSeed, seed);
37+
Assert.AreEqual(expectedVal, result);
38+
}
39+
40+
41+
}
42+
}

Tests/Tests.csproj

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{A10F28EF-0CFC-48A7-B735-B32B4A103C50}</ProjectGuid>
8+
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>Tests</RootNamespace>
12+
<AssemblyName>Tests</AssemblyName>
13+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="System" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="System.Data" />
39+
<Reference Include="System.Xml" />
40+
<Reference Include="nunit.framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb">
41+
<HintPath>..\packages\NUnit.3.5.0\lib\net45\nunit.framework.dll</HintPath>
42+
</Reference>
43+
</ItemGroup>
44+
<ItemGroup>
45+
<Compile Include="Tests.cs" />
46+
<Compile Include="Properties\AssemblyInfo.cs" />
47+
</ItemGroup>
48+
<ItemGroup>
49+
<ProjectReference Include="..\Minecraft Enchantment Cracker\Minecraft Enchantment Cracker.csproj">
50+
<Project>{def0a159-01dc-4467-8cb0-45533335c177}</Project>
51+
<Name>Minecraft Enchantment Cracker</Name>
52+
</ProjectReference>
53+
</ItemGroup>
54+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
55+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
56+
Other similar extension points exist, see Microsoft.Common.targets.
57+
<Target Name="BeforeBuild">
58+
</Target>
59+
<Target Name="AfterBuild">
60+
</Target>
61+
-->
62+
63+
</Project>

Tests/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="NUnit" version="3.5.0" targetFramework="net45" />
4+
</packages>

0 commit comments

Comments
 (0)