Add parsing for binary floats

This commit is contained in:
Nathan McRae
2024-02-16 21:26:35 -08:00
parent 96d408386b
commit 8795a2873a
2 changed files with 69 additions and 14 deletions

View File

@ -1,4 +1,5 @@
using NathanMcRae;
using System.Linq;
using System.Text;
{
@ -68,6 +69,24 @@ using System.Text;
}
}
{
string testName = "Float binary test";
var bytes = new List<byte>();
bytes.AddRange(Encoding.UTF8.GetBytes("somefloat:float64\tbinfloat:float64-le" +
"\n1.5\t")); bytes.AddRange(BitConverter.GetBytes(1.5));
bytes.AddRange(Encoding.UTF8.GetBytes("\n-8.0000005E-14\t")); bytes.AddRange(BitConverter.GetBytes(-8.0000005E-14));
SaneTsv parsed = SaneTsv.ParseTypedTsv(bytes.ToArray());
if ((double)parsed.Records[0]["binfloat"] == (double)parsed.Records[0]["somefloat"])
{
Console.WriteLine($"Passed {testName}");
}
else
{
Console.WriteLine($"Failed {testName}");
}
}
Console.WriteLine("Done with tests");