Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions MEOS.NET.Tests/CountedArrayTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using MEOS.NET.Enums;
using MEOS.NET.Types;

namespace MEOS.NET.Tests
{
/// <summary>
/// MEOS reads an array of its own values through a pointer to the first
/// element and a count, so a method taking one takes a C# array and answers
/// its length to MEOS.
/// </summary>
[TestClass]
public class CountedArrayTests : MeosTest
{
[TestMethod]
public void ASequenceIsMadeOfItsInstants()
{
Temporal[] instants =
[
TFloat.In("25.0@2024-12-06")!,
TFloat.In("27.0@2024-12-07")!,
TFloat.In("30.0@2024-12-09")!,
];

Temporal sequence = TSequence.Make(instants, true, true, InterpType.Linear, true)!;

Assert.AreEqual(3, sequence.NumInstants());
Assert.AreEqual(
"[25@2024-12-06 00:00:00+00, 27@2024-12-07 00:00:00+00, 30@2024-12-09 00:00:00+00]",
sequence.ToString());
}

[TestMethod]
public void MergingAnArrayOfTemporalValuesJoinsThem()
{
Temporal[] parts =
[
TFloat.In("[25.0@2024-12-06, 27.0@2024-12-07]")!,
TFloat.In("[30.0@2024-12-09, 32.0@2024-12-10]")!,
];

Temporal merged = Temporal.MergeArray(parts)!;

Assert.AreEqual(4, merged.NumInstants());
Assert.AreEqual(2, merged.NumSequences());
}

[TestMethod]
public void AnEmptyArrayIsARequestMeosRefuses()
{
Assert.ThrowsException<MEOS.NET.Exceptions.MEOSInvalidArgValueException>(
() => TSequence.Make([], true, true, InterpType.Linear, true));
}
}
}
53 changes: 53 additions & 0 deletions MEOS.NET.Tests/OutParameterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using MEOS.NET.Types;

namespace MEOS.NET.Tests
{
/// <summary>
/// MEOS answers some values through an out-parameter and returns whether the
/// value exists at all, so those methods answer the value or null.
/// </summary>
[TestClass]
public class OutParameterTests : MeosTest
{
[TestMethod]
public void ABoxAnswersTheBoundsItHas()
{
TBox box = TBox.In("TBOXFLOAT XT([1.0, 3.0],[2024-12-06, 2024-12-08])")!;

Assert.AreEqual(1.0, box.Xmin());
Assert.AreEqual(3.0, box.Xmax());
Assert.AreEqual(true, box.TminInc());
}

[TestMethod]
public void ABoxAnswersNullForABoundItDoesNotHave()
{
TBox box = TBox.In("TBOX T([2024-12-06, 2024-12-08])")!;

Assert.IsNull(box.Xmin());
Assert.IsNull(box.Xmax());
Assert.IsNotNull(box.TminInc());
}

[TestMethod]
public void ASetAnswersTheValueAtAnIndex()
{
Set set = FloatSet.In("{1.5, 2.5, 3.5}")!;

Assert.AreEqual(1.5, ((FloatSet)set).ValueN(1));
Assert.AreEqual(3.5, ((FloatSet)set).ValueN(3));
Assert.IsNull(((FloatSet)set).ValueN(4));
}

[TestMethod]
public void ATemporalFloatAnswersItsValueAtAMoment()
{
TFloat temp = (TFloat)TFloat.In("[25.0@2024-12-06, 27.0@2024-12-08]")!;

Assert.AreEqual(25.0,
temp.ValueAtTimestamptz(new DateTime(2024, 12, 6, 0, 0, 0, DateTimeKind.Utc), true));
Assert.IsNull(
temp.ValueAtTimestamptz(new DateTime(2024, 12, 9, 0, 0, 0, DateTimeKind.Utc), true));
}
}
}
20 changes: 20 additions & 0 deletions MEOS.NET/Types/BigIntSet.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down Expand Up @@ -27,6 +29,24 @@ public string Out()
public long StartValue()
=> Meos.BigintsetStartValue(this.Ptr);

public long? ValueN(int n)
{
IntPtr _result = Marshal.AllocHGlobal(8);
try
{
if (!Meos.BigintsetValueN(this.Ptr, n, _result))
{
return null;
}

return Marshal.ReadInt64(_result);
}
finally
{
Marshal.FreeHGlobal(_result);
}
}

public long[] Values()
=> Meos.BigintsetValues(this.Ptr);

Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Types/BigIntSpan.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Types/BigIntSpanSet.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Types/Box.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Types/CbufferSet.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Types/Collection.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down
20 changes: 20 additions & 0 deletions MEOS.NET/Types/DateSet.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down Expand Up @@ -30,6 +32,24 @@ public DateOnly StartValue()
public Set? ToTstzset()
=> MEOSFactory.WrapSet(Meos.DatesetToTstzset(this.Ptr));

public DateOnly? ValueN(int n)
{
IntPtr _result = Marshal.AllocHGlobal(4);
try
{
if (!Meos.DatesetValueN(this.Ptr, n, _result))
{
return null;
}

return MEOSConvert.ToDateOnly(Marshal.ReadInt32(_result));
}
finally
{
Marshal.FreeHGlobal(_result);
}
}

public int[] Values()
=> Meos.DatesetValues(this.Ptr);

Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Types/DateSpan.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down
20 changes: 20 additions & 0 deletions MEOS.NET/Types/DateSpanSet.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand All @@ -15,6 +17,24 @@ internal DateSpanSet(IntPtr ptr) : base(ptr) { }
public override string ToString()
=> this.Out();

public DateOnly? DateN(int n)
{
IntPtr _result = Marshal.AllocHGlobal(4);
try
{
if (!Meos.DatespansetDateN(this.Ptr, n, _result))
{
return null;
}

return MEOSConvert.ToDateOnly(Marshal.ReadInt32(_result));
}
finally
{
Marshal.FreeHGlobal(_result);
}
}

public Set? Dates()
=> MEOSFactory.WrapSet(Meos.DatespansetDates(this.Ptr));

Expand Down
20 changes: 20 additions & 0 deletions MEOS.NET/Types/FloatSet.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down Expand Up @@ -42,6 +44,24 @@ public double StartValue()
public Set? ToIntset()
=> MEOSFactory.WrapSet(Meos.FloatsetToIntset(this.Ptr));

public double? ValueN(int n)
{
IntPtr _result = Marshal.AllocHGlobal(8);
try
{
if (!Meos.FloatsetValueN(this.Ptr, n, _result))
{
return null;
}

return Marshal.PtrToStructure<double>(_result);
}
finally
{
Marshal.FreeHGlobal(_result);
}
}

public double[] Values()
=> Meos.FloatsetValues(this.Ptr);

Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Types/FloatSpan.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Types/FloatSpanSet.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Types/GeogSet.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Types/GeomSet.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down
20 changes: 20 additions & 0 deletions MEOS.NET/Types/IntSet.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down Expand Up @@ -30,6 +32,24 @@ public int StartValue()
public Set? ToFloatset()
=> MEOSFactory.WrapSet(Meos.IntsetToFloatset(this.Ptr));

public int? ValueN(int n)
{
IntPtr _result = Marshal.AllocHGlobal(4);
try
{
if (!Meos.IntsetValueN(this.Ptr, n, _result))
{
return null;
}

return Marshal.ReadInt32(_result);
}
finally
{
Marshal.FreeHGlobal(_result);
}
}

public int[] Values()
=> Meos.IntsetValues(this.Ptr);

Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Types/IntSpan.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Types/IntSpanSet.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Types/NpointSet.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down
2 changes: 2 additions & 0 deletions MEOS.NET/Types/PoseSet.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#nullable enable

using System.Runtime.InteropServices;

using MEOS.NET.Enums;
using MEOS.NET.Functions;

Expand Down
Loading
Loading