Add basic implementation of physical units
Serde still isn't working, need to store the exact format of the unit as specified in the attribute
This commit is contained in:
@ -15,6 +15,15 @@ internal class Program : SaneTsv
|
||||
public DateTime Column3 { get; set; }
|
||||
}
|
||||
|
||||
public class UnitTest : SaneTsv.CommentedTsvRecord
|
||||
{
|
||||
[SaneTsv.TypedTsvColumn("id")]
|
||||
public UInt32 Id { get; set; }
|
||||
|
||||
[SaneTsv.TypedTsvColumn("value", "m/s:ph-unit:float64")]
|
||||
public UnitsNet.Speed Value { get; set; }
|
||||
}
|
||||
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
{
|
||||
@ -35,6 +44,24 @@ internal class Program : SaneTsv
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
string testName = "Bad date column name";
|
||||
string testString1 = "# ExtraTSV V0.0.1\n" +
|
||||
"column1:ty\\#pe:boolean\tcolumn2:binary\tiso8601:string" +
|
||||
"\nTRUE\tvalue\\\\t\0woo\t2024-02-15T18:03:30.0000" +
|
||||
"\nFALSE\tnother\t2024-02-15T18:03:39.0001";
|
||||
|
||||
try
|
||||
{
|
||||
CommentedTsv<DateTest> parsed = SaneTsv.ParseExtraTsv<DateTest>(Encoding.UTF8.GetBytes(testString1));
|
||||
Console.WriteLine($"Failed {testName}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"Passed {testName}");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
string testName = "Serde date";
|
||||
string testString1 = "# ExtraTSV V0.0.1\n" +
|
||||
@ -54,6 +81,43 @@ internal class Program : SaneTsv
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
string testName = "Parse unit";
|
||||
string testString1 = "# ExtraTSV V0.0.1\n" +
|
||||
"id:uint32\tvalue:m/s:ph-unit:float64\n" +
|
||||
"0\t1.5\n" +
|
||||
"1\t5.4e3";
|
||||
|
||||
CommentedTsv<UnitTest> parsed = SaneTsv.ParseExtraTsv<UnitTest>(Encoding.UTF8.GetBytes(testString1));
|
||||
if (parsed.Records[0].Value.Value == 1.5)
|
||||
{
|
||||
Console.WriteLine($"Passed {testName}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Failed {testName}");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
string testName = "Serde unit";
|
||||
string testString1 = "# ExtraTSV V0.0.1\n" +
|
||||
"id:uint32\tvalue:m/s:ph-unit:float64\n" +
|
||||
"0\t1.5\n" +
|
||||
"1\t5.4e3";
|
||||
|
||||
CommentedTsv<UnitTest> parsed = SaneTsv.ParseExtraTsv<UnitTest>(Encoding.UTF8.GetBytes(testString1));
|
||||
string serialized = Encoding.UTF8.GetString(SaneTsv.SerializeExtraTsv<UnitTest>(parsed.Records));
|
||||
if (testString1 == serialized)
|
||||
{
|
||||
Console.WriteLine($"Passed {testName}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Failed {testName}");
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Done with tests");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user