Created
March 24, 2017 00:21
-
-
Save JamesNK/4e6bee576196be016fdd31a3dbe0880e to your computer and use it in GitHub Desktop.
Json.NET double tester - Program.cs
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
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Newtonsoft.Json; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
private static bool Exit; | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Hi!"); | |
var t = Task.Run(TestDoubles); | |
Console.ReadKey(); | |
Exit = true; | |
t.Wait(); | |
} | |
public static double NextDouble( | |
Random random, | |
double minValue, | |
double maxValue) | |
{ | |
return random.NextDouble() * (maxValue - minValue) + minValue; | |
} | |
private static Task TestDoubles() | |
{ | |
Random random = new Random(); | |
while (!Exit) | |
{ | |
int a = random.Next(0, int.MaxValue); | |
int b = random.Next(0, int.MaxValue); | |
bool negative = random.NextDouble() >= 0.5; | |
string doubleText = ((negative) ? "-" : string.Empty) + a + "." + b; | |
StringReader sr = new StringReader(doubleText); | |
JsonTextReader reader = new JsonTextReader(sr); | |
double? d = reader.ReadAsDouble(); | |
double expected = double.Parse(doubleText); | |
if (d.Value != expected) | |
{ | |
File.AppendAllText("incorrect.txt", doubleText + Environment.NewLine); | |
} | |
} | |
return Task.FromResult(true); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment