-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly deduces and manages decimal separator
- Loading branch information
Showing
9 changed files
with
324 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{64A2D360-A3A2-4F87-8983-EC4A18E8F053}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<RootNamespace>ColoradoTests</RootNamespace> | ||
<AssemblyName>ColoradoTests</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug</OutputPath> | ||
<DefineConstants>DEBUG;</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>false</ConsolePause> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>full</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<ConsolePause>false</ConsolePause> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="nunit.framework"> | ||
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Test.cs" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Colorado.csproj"> | ||
<Project>{12F5964C-2BDE-4379-915B-E55322B5DE75}</Project> | ||
<Name>Colorado</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using NUnit.Framework; | ||
using System; | ||
|
||
using Colorado.Core; | ||
|
||
namespace ColoradoTests { | ||
[TestFixture] | ||
public class TestDecimalMark { | ||
[Test] | ||
public void TestDecimalSeparator() { | ||
for (int i = 0; i < DecimalMark.DecimalSeparatorChar.Count; ++i) { | ||
Assert.AreEqual( | ||
DecimalMark.DecimalSeparatorChar[ i ], | ||
DecimalMark.AsChar( (DecimalMark.DecimalSeparator) i ) | ||
); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestIsDecimalMark() { | ||
Assert.AreEqual( false, DecimalMark.IsDecimalMark( 'a' ) ); | ||
Assert.AreEqual( true, DecimalMark.IsDecimalMark( '.' ) ); | ||
Assert.AreEqual( true, DecimalMark.IsDecimalMark( ',' ) ); | ||
} | ||
|
||
[Test] | ||
public void TestWhichDecimalMark() { | ||
Assert.AreEqual( DecimalMark.DecimalSeparator.Point, DecimalMark.WhichDecimalMark( "4" ) ); | ||
Assert.AreEqual( DecimalMark.DecimalSeparator.Point, DecimalMark.WhichDecimalMark( "4.5" ) ); | ||
Assert.AreEqual( DecimalMark.DecimalSeparator.Comma, DecimalMark.WhichDecimalMark( "4,5" ) ); | ||
|
||
Assert.AreEqual( 0, DecimalMark.WhichDecimalMark( '.' ) ); | ||
Assert.AreEqual( 1, DecimalMark.WhichDecimalMark( ',' ) ); | ||
Assert.AreEqual( -1, DecimalMark.WhichDecimalMark( 'a' ) ); | ||
} | ||
|
||
[Test] | ||
public void TestIsNumber() | ||
{ | ||
string[] testNumbers = { | ||
"", " ", ".0", | ||
"-.1", "-.", "0.4e-5", | ||
"5.4", "0", "+", | ||
"+.0", "0,6e-6", "5,6", | ||
"hello4", "4d", "3", | ||
"0.4e5", "0,1E45", "0,0001", | ||
",1", "1,", "1.", | ||
}; | ||
|
||
bool[] testResults = { | ||
false, false, true, | ||
true, false, true, | ||
true, true, false, | ||
true, true, true, | ||
false, false, true, | ||
true, true, true, | ||
true, true, true, | ||
}; | ||
|
||
for(int i = 0; i < testResults.Length; ++i) { | ||
double num; | ||
bool actualResult = double.TryParse( testNumbers[ i ], out num ); | ||
bool result = DecimalMark.IsNumber( testNumbers[ i ] ); | ||
|
||
Console.WriteLine( "[\"{0}\"] -> {1} == {2} == {3} == {4}?", | ||
testNumbers[ i ], testResults[ i ], result, actualResult, num ); | ||
|
||
Assert.AreEqual( testResults[ i ], result ); | ||
Assert.AreEqual( testResults[ i ], actualResult ); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestIsRealNumber() | ||
{ | ||
string[] testNumbers = { | ||
"", " ", ".0", | ||
"4e+5", "-.", "4", | ||
"5.4", "0", "+", | ||
"+.0", "0,6e-6", "5,6", | ||
"hello4", "4d", "0,", | ||
"0.4e5", "0,1E45", "0,0001", | ||
}; | ||
|
||
bool[] testResults = { | ||
false, false, true, | ||
false, false, false, | ||
true, false, false, | ||
true, true, true, | ||
false, false, true, | ||
true, true, true, | ||
}; | ||
|
||
for(int i = 0; i < testResults.Length; ++i) { | ||
bool result = DecimalMark.IsRealNumber( testNumbers[ i ] ); | ||
|
||
Console.WriteLine( "[\"{0}\"] -> {1} == {2}?", | ||
testNumbers[ i ], testResults[ i ], result ); | ||
|
||
Assert.AreEqual( testResults[ i ], result ); | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="NUnit" version="2.6.3" targetFramework="net45" /> | ||
</packages> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.