Permalink
Browse files

JFLibrary tests

  • Loading branch information...
1 parent ee89c25 commit 74391e66c85eac191e01d22df989b7c3f0c4527c unknown committed Jun 24, 2011
View
@@ -5,7 +5,19 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JFLibrary", "JFLibrary\JFLi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JFLibrary.Azure", "JFLibrary.Azure\JFLibrary.Azure.csproj", "{E1D05325-CFFA-4A61-8543-82C090A27908}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JFLibraryTest", "JFLibraryTest\JFLibraryTest.csproj", "{E58B63A7-F4A0-4C17-A370-F1020518C061}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{24EEC224-5F51-4B48-A3A0-D0EE8149C9C2}"
+ ProjectSection(SolutionItems) = preProject
+ JFLibrary.vsmdi = JFLibrary.vsmdi
+ Local.testsettings = Local.testsettings
+ TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
+ EndProjectSection
+EndProject
Global
+ GlobalSection(TestCaseManagementSettings) = postSolution
+ CategoryFile = JFLibrary.vsmdi
+ EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
@@ -19,6 +31,10 @@ Global
{E1D05325-CFFA-4A61-8543-82C090A27908}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E1D05325-CFFA-4A61-8543-82C090A27908}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E1D05325-CFFA-4A61-8543-82C090A27908}.Release|Any CPU.Build.0 = Release|Any CPU
+ {E58B63A7-F4A0-4C17-A370-F1020518C061}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {E58B63A7-F4A0-4C17-A370-F1020518C061}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {E58B63A7-F4A0-4C17-A370-F1020518C061}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {E58B63A7-F4A0-4C17-A370-F1020518C061}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
View
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
+ <TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
+ <RunConfiguration id="70b10f88-c012-439e-bd16-d1a064c84b96" name="Local" storage="local.testsettings" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+ </TestList>
+</TestLists>
@@ -0,0 +1,212 @@
+using System;
+using System.Text;
+using System.Collections.Generic;
+using System.Linq;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using JFLibrary;
+
+namespace JFLibraryTest
+{
+ /// <summary>
+ /// Tests for DateSpan
+ /// </summary>
+ [TestClass]
+ public class DateSpanTest
+ {
+ [TestMethod]
+ public void SameYearTests()
+ {
+ Console.WriteLine("Same year tests");
+
+ // same date
+ TestDateSpan(
+ new DateTime(2011, 1, 2),
+ new DateTime(2011, 1, 2),
+ days: 0);
+
+ // one day
+ TestDateSpan(
+ new DateTime(2011, 1, 1),
+ new DateTime(2011, 1, 2),
+ days: 1);
+
+ // one month
+ TestDateSpan(
+ new DateTime(2011, 1, 1),
+ new DateTime(2011, 2, 1),
+ months: 1);
+
+ // several months
+ TestDateSpan(
+ new DateTime(2011, 1, 1),
+ new DateTime(2011, 4, 10),
+ months: 3,
+ days: 9);
+
+ // less than a month, across boundary
+ TestDateSpan(
+ new DateTime(2011, 1, 25),
+ new DateTime(2011, 2, 1),
+ days: 7);
+ }
+
+ [TestMethod]
+ public void PreviousYearTests()
+ {
+ Console.WriteLine("Previous year tests");
+
+ // one year
+ TestDateSpan(
+ new DateTime(2010, 1, 1),
+ new DateTime(2011, 1, 1),
+ years: 1);
+
+ // more than a year
+ TestDateSpan(
+ new DateTime(2010, 2, 1),
+ new DateTime(2011, 5, 5),
+ years: 1,
+ months: 3,
+ days: 4);
+
+ // less than a year, across boundary
+ TestDateSpan(
+ new DateTime(2010, 2, 1),
+ new DateTime(2011, 1, 1),
+ months: 11);
+
+ // across month and year boundary
+ TestDateSpan(
+ new DateTime(2010, 1, 25),
+ new DateTime(2011, 2, 1),
+ years: 1,
+ months: 0,
+ days: 7);
+ }
+
+ [TestMethod]
+ public void MultiYearTest()
+ {
+ Console.WriteLine("Multi-year tests");
+
+ // two years
+ TestDateSpan(
+ new DateTime(2009, 1, 1),
+ new DateTime(2011, 1, 1),
+ years: 2);
+
+ // across month and year boundary
+ TestDateSpan(
+ new DateTime(2009, 1, 25),
+ new DateTime(2011, 2, 1),
+ years: 2,
+ months: 0,
+ days: 7);
+ }
+
+ [TestMethod]
+ public void LeapYearTest()
+ {
+ Console.WriteLine("Leap year tests");
+
+ // three years with start as leap day
+ TestDateSpan(
+ new DateTime(2008, 2, 29),
+ new DateTime(2011, 2, 28),
+ years: 3);
+
+ // between two leap years
+ TestDateSpan(
+ new DateTime(2008, 2, 29),
+ new DateTime(2012, 2, 29),
+ years: 4);
+
+ // last day of month is bigger
+ TestDateSpan(
+ new DateTime(2007, 7, 30),
+ new DateTime(2008, 2, 29),
+ years: 0,
+ months: 7,
+ days: 0);
+
+ // across month and year boundary
+ TestDateSpan(
+ new DateTime(2008, 2, 25),
+ new DateTime(2011, 3, 1),
+ years: 3,
+ months: 0,
+ days: 4);
+
+ TestDateSpan(
+ new DateTime(2011, 2, 25),
+ new DateTime(2012, 3, 1),
+ years: 1,
+ months: 0,
+ days: 5);
+ }
+
+ [TestMethod]
+ public void July4Test()
+ {
+ DateTime today = new DateTime(2011, 6, 22);
+
+ DateTime declarationOfIndependence = new DateTime(1776, 7, 4);
+ TimeSpan ageTimeSpan = today.Subtract(declarationOfIndependence);
+ Console.WriteLine("The US is {0} days old.", ageTimeSpan.TotalDays);
+ // The US is 85819 days old.
+
+ // flawed conversion to years
+ Console.WriteLine(
+ "{0} years old. (incorrect)",
+ Math.Floor((today - declarationOfIndependence).TotalDays / 365));
+ // 235 years old. (incorrect)
+ }
+
+
+ [TestMethod]
+ public void UserMembershipTest()
+ {
+ Console.WriteLine("User membership test");
+
+ // user who joined 2 years ago
+ DateTime joined = new DateTime(2008, 6, 22);
+ DateTime today = new DateTime(2011, 6, 22);
+
+ Console.WriteLine(
+ "Joined {0} years ago. (incorrect)",
+ Math.Floor((today - joined).TotalDays / 365.2425));
+ // Joined 2 years ago. (incorrect)
+
+ TestDateSpan(joined, today, years: 3);
+ }
+
+ [TestMethod]
+ public void IraqWarTest()
+ {
+ DateTime warBegan = new DateTime(2003, 3, 20);
+ DateTime warEnded = new DateTime(2010, 8, 31);
+ DateSpan warLength = new DateSpan(warBegan, warEnded);
+ Console.WriteLine("The Iraq War lasted {0}.", warLength.ToString());
+ //The Iraq War lasted 7 years, 5 months, 11 days.
+
+ TestDateSpan(warBegan, warEnded, years: 7, months: 5, days: 11);
+ }
+
+ private static void TestDateSpan(
+ DateTime startDate,
+ DateTime endDate,
+ int years = 0, int months = 0, int days = 0)
+ {
+ DateSpan diff = new DateSpan(startDate, endDate);
+ Console.WriteLine(
+ "{0} - {1} : {2}",
+ startDate.ToShortDateString(),
+ endDate.ToShortDateString(),
+ diff.ToString());
+
+ Assert.IsTrue(
+ diff.Years == years && diff.Months == months && diff.Days == days,
+ String.Format("FAILURE: expected {0} years, {1} months, {2} days", years, months, days));
+ }
+ }
+}
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>
+ </ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{E58B63A7-F4A0-4C17-A370-F1020518C061}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>JFLibraryTest</RootNamespace>
+ <AssemblyName>JFLibraryTest</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ </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="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
+ <Reference Include="System" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="DateSpanTest.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\JFLibrary\JFLibrary.csproj">
+ <Project>{8CE1C528-895D-4BFC-83F8-AD6C8EC0DDB1}</Project>
+ <Name>JFLibrary</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildBinPath)\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>
@@ -0,0 +1,35 @@
+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("JFLibraryTest")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Joel Fillmore")]
+[assembly: AssemblyProduct("JFLibraryTest")]
+[assembly: AssemblyCopyright("Copyright © Joel Fillmore 2011")]
+[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("de9a2048-2c78-4c83-9cec-d63629dab1cc")]
+
+// 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.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
View
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<TestSettings name="Local" id="70b10f88-c012-439e-bd16-d1a064c84b96" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
+ <Description>These are default test settings for a local test run.</Description>
+ <Deployment enabled="false" />
+ <Execution>
+ <TestTypeSpecific />
+ <AgentRule name="Execution Agents">
+ </AgentRule>
+ </Execution>
+</TestSettings>
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<TestSettings name="Trace and Test Impact" id="7b84fd25-84b8-4b9f-8e08-2a332e785663" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
+ <Description>These are test settings for Trace and Test Impact.</Description>
+ <Execution>
+ <TestTypeSpecific />
+ <AgentRule name="Execution Agents">
+ <DataCollectors>
+ <DataCollector uri="datacollector://microsoft/SystemInfo/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TestTools.DataCollection.SystemInfo.SystemInfoDataCollector, Microsoft.VisualStudio.TestTools.DataCollection.SystemInfo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="System Information">
+ </DataCollector>
+ <DataCollector uri="datacollector://microsoft/ActionLog/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TestTools.ManualTest.ActionLog.ActionLogPlugin, Microsoft.VisualStudio.TestTools.ManualTest.ActionLog, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="Actions">
+ </DataCollector>
+ <DataCollector uri="datacollector://microsoft/HttpProxy/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TraceCollector.HttpProxyCollector, Microsoft.VisualStudio.TraceCollector, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="ASP.NET Client Proxy for IntelliTrace and Test Impact">
+ </DataCollector>
+ <DataCollector uri="datacollector://microsoft/TestImpact/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TraceCollector.TestImpactDataCollector, Microsoft.VisualStudio.TraceCollector, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="Test Impact">
+ </DataCollector>
+ <DataCollector uri="datacollector://microsoft/TraceDebugger/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TraceCollector.TraceDebuggerDataCollector, Microsoft.VisualStudio.TraceCollector, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="IntelliTrace">
+ </DataCollector>
+ </DataCollectors>
+ </AgentRule>
+ </Execution>
+</TestSettings>

0 comments on commit 74391e6

Please sign in to comment.