mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-03-21 17:48:28 -05:00
Added tests for DateUtil
This commit is contained in:
parent
4669551d77
commit
9852c42ca1
19
PKHeX.sln
19
PKHeX.sln
|
|
@ -5,18 +5,37 @@ VisualStudioVersion = 14.0.25420.1
|
|||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PKHeX", "PKHeX\PKHeX.csproj", "{B4EFF030-C75A-49F9-A4BC-738D1B61C4AF}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PKHeX.Tests", "Tests\PKHeX.Tests\PKHeX.Tests.csproj", "{8E2499BC-C11A-4809-8737-66D35A625425}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{7C0598C9-DDF3-4ACC-B15D-6A626ADB7530}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Debug|x86 = Debug|x86
|
||||
Release|Any CPU = Release|Any CPU
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{B4EFF030-C75A-49F9-A4BC-738D1B61C4AF}.Debug|Any CPU.ActiveCfg = Debug|x86
|
||||
{B4EFF030-C75A-49F9-A4BC-738D1B61C4AF}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{B4EFF030-C75A-49F9-A4BC-738D1B61C4AF}.Debug|x86.Build.0 = Debug|x86
|
||||
{B4EFF030-C75A-49F9-A4BC-738D1B61C4AF}.Release|Any CPU.ActiveCfg = Release|x86
|
||||
{B4EFF030-C75A-49F9-A4BC-738D1B61C4AF}.Release|x86.ActiveCfg = Release|x86
|
||||
{B4EFF030-C75A-49F9-A4BC-738D1B61C4AF}.Release|x86.Build.0 = Release|x86
|
||||
{8E2499BC-C11A-4809-8737-66D35A625425}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8E2499BC-C11A-4809-8737-66D35A625425}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8E2499BC-C11A-4809-8737-66D35A625425}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{8E2499BC-C11A-4809-8737-66D35A625425}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{8E2499BC-C11A-4809-8737-66D35A625425}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8E2499BC-C11A-4809-8737-66D35A625425}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8E2499BC-C11A-4809-8737-66D35A625425}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{8E2499BC-C11A-4809-8737-66D35A625425}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{8E2499BC-C11A-4809-8737-66D35A625425} = {7C0598C9-DDF3-4ACC-B15D-6A626ADB7530}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public static bool IsDateValid(int year, int month, int day)
|
|||
/// <returns>A boolean indicating whether or not the date is valid.</returns>
|
||||
public static bool IsDateValid(uint year, uint month, uint day)
|
||||
{
|
||||
return !(year < 0 || year > DateTime.MaxValue.Year || month < 1 || month > 12 || day < 1 || day > DateTime.DaysInMonth((int)year, (int)month));
|
||||
return year < int.MaxValue && month < int.MaxValue && day < int.MaxValue && IsDateValid((int)year, (int)month, (int)day);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
89
Tests/PKHeX.Tests/PKHeX.Tests.csproj
Normal file
89
Tests/PKHeX.Tests/PKHeX.Tests.csproj
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{8E2499BC-C11A-4809-8737-66D35A625425}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>PKHeX.Tests</RootNamespace>
|
||||
<AssemblyName>PKHeX.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||
<IsCodedUITest>False</IsCodedUITest>
|
||||
<TestProjectType>UnitTest</TestProjectType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||
</ItemGroup>
|
||||
</When>
|
||||
<Otherwise>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
|
||||
</ItemGroup>
|
||||
</Otherwise>
|
||||
</Choose>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Util\DateUtilTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\PKHeX\PKHeX.csproj">
|
||||
<Project>{b4eff030-c75a-49f9-a4bc-738d1b61c4af}</Project>
|
||||
<Name>PKHeX</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Choose>
|
||||
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</When>
|
||||
</Choose>
|
||||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
36
Tests/PKHeX.Tests/Properties/AssemblyInfo.cs
Normal file
36
Tests/PKHeX.Tests/Properties/AssemblyInfo.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("PKHeX.Tests")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("PKHeX.Tests")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("8e2499bc-c11a-4809-8737-66d35a625425")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
112
Tests/PKHeX.Tests/Util/DateUtilTests.cs
Normal file
112
Tests/PKHeX.Tests/Util/DateUtilTests.cs
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PKHeX.Tests.Util
|
||||
{
|
||||
[TestClass]
|
||||
public class DateUtilTests
|
||||
{
|
||||
const string DateUtilCategory = "Date Util Tests";
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(DateUtilCategory)]
|
||||
public void RecognizesCorrectDates()
|
||||
{
|
||||
Assert.IsTrue(PKHeX.Util.IsDateValid(2000, 1, 1), "Failed to recognize 1/1/2000");
|
||||
Assert.IsTrue(PKHeX.Util.IsDateValid(2001, 1, 31), "Failed to recognize 1/31/2001");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(DateUtilCategory)]
|
||||
public void MonthBoundaries()
|
||||
{
|
||||
Assert.IsTrue(PKHeX.Util.IsDateValid(2016, 1, 31), "Incorrect month boundary for January");
|
||||
Assert.IsTrue(PKHeX.Util.IsDateValid(2016, 2, 28), "Incorrect month boundary for February");
|
||||
Assert.IsTrue(PKHeX.Util.IsDateValid(2016, 3, 31), "Incorrect month boundary for March");
|
||||
Assert.IsTrue(PKHeX.Util.IsDateValid(2016, 4, 30), "Incorrect month boundary for April");
|
||||
Assert.IsTrue(PKHeX.Util.IsDateValid(2016, 5, 31), "Incorrect month boundary for May");
|
||||
Assert.IsTrue(PKHeX.Util.IsDateValid(2016, 6, 30), "Incorrect month boundary for June");
|
||||
Assert.IsTrue(PKHeX.Util.IsDateValid(2016, 7, 31), "Incorrect month boundary for July");
|
||||
Assert.IsTrue(PKHeX.Util.IsDateValid(2016, 8, 31), "Incorrect month boundary for August");
|
||||
Assert.IsTrue(PKHeX.Util.IsDateValid(2016, 9, 30), "Incorrect month boundary for September");
|
||||
Assert.IsTrue(PKHeX.Util.IsDateValid(2016, 10, 31), "Incorrect month boundary for October");
|
||||
Assert.IsTrue(PKHeX.Util.IsDateValid(2016, 11, 30), "Incorrect month boundary for November");
|
||||
Assert.IsTrue(PKHeX.Util.IsDateValid(2016, 12, 31), "Incorrect month boundary for December");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(DateUtilCategory)]
|
||||
public void RecognizeCorrectLeapYear()
|
||||
{
|
||||
Assert.IsTrue(PKHeX.Util.IsDateValid(2004, 2, 29));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(DateUtilCategory)]
|
||||
public void FailsWithIncorrectLeapYear()
|
||||
{
|
||||
Assert.IsFalse(PKHeX.Util.IsDateValid(2005, 2, 29));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(DateUtilCategory)]
|
||||
public void FailsWithZeroDate()
|
||||
{
|
||||
Assert.IsFalse(PKHeX.Util.IsDateValid(0, 0, 0));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(DateUtilCategory)]
|
||||
public void FailsWithNegativeDate()
|
||||
{
|
||||
Assert.IsFalse(PKHeX.Util.IsDateValid(-1, -1, -1));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(DateUtilCategory)]
|
||||
public void FailsWithBigDay()
|
||||
{
|
||||
Assert.IsFalse(PKHeX.Util.IsDateValid(2000, 1, 32));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(DateUtilCategory)]
|
||||
public void FailsWithBigMonth()
|
||||
{
|
||||
Assert.IsFalse(PKHeX.Util.IsDateValid(2000, 13, 1));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(DateUtilCategory)]
|
||||
public void FailsWithBigYear()
|
||||
{
|
||||
Assert.IsFalse(PKHeX.Util.IsDateValid(10000, 1, 1));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(DateUtilCategory)]
|
||||
public void FailsWithZeroDay()
|
||||
{
|
||||
Assert.IsFalse(PKHeX.Util.IsDateValid(2000, 1, 0));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(DateUtilCategory)]
|
||||
public void FailsWithZeroMonth()
|
||||
{
|
||||
Assert.IsFalse(PKHeX.Util.IsDateValid(2000, 0, 1));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(DateUtilCategory)]
|
||||
public void TestUIntOverload()
|
||||
{
|
||||
Assert.IsTrue(PKHeX.Util.IsDateValid((uint)2000, (uint)1, (uint)1), "Failed 1/1/2000");
|
||||
Assert.IsFalse(PKHeX.Util.IsDateValid(uint.MaxValue, uint.MaxValue, uint.MaxValue), "Failed with uint.MaxValue");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user