Skip to content

Commit

Permalink
Update Primitive.Array.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
alec1o committed May 31, 2024
1 parent 2a60dcd commit 1661aa5
Showing 1 changed file with 148 additions and 0 deletions.
148 changes: 148 additions & 0 deletions test/primitive/Primitive.Array.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using System;
using System.Collections.Generic;
using Byter;
using Xunit;

namespace Test.Primitives;
Expand All @@ -7,5 +10,150 @@ public partial class Primitives
[Fact]
public void _Array()
{
_Array1();
_Array2();
_Array3();
}

private void _Array1()
{
Primitive primitive = new();

string[] list =
[

Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
];

primitive.Add.Array(list);

Assert.Equal(list, primitive.Get.Array<string>());
Assert.True(primitive.IsValid);
}

private void _Array2()
{
Primitive primitive = new();

List<string>[] list = new List<List<string>>
{
new()
{
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
},
new()
{
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
},
new()
{
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
},
}.ToArray();

primitive.Add.Array(list);

var myList = primitive.Get.Array<List<string>>();
Assert.Equal(list, myList);
for (int i = 0; i < list.Length; i++)
{
Assert.Equal(list[i], myList[i]);
}

Assert.True(primitive.IsValid);
}

private void _Array3()
{
Primitive primitive = new();

Array3Info[] list = new List<Array3Info>
{
new()
{
Number = int.MaxValue,
String = Guid.NewGuid().ToString(),
Bool = true,
List =
[
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString()
],
Array =
[
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString()
],
SubClass = new()
{
String = Guid.NewGuid().ToString()
}
},
new()
{
Number = int.MinValue,
String = Guid.NewGuid().ToString(),
Bool = false,
List =
[
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString()
],
Array =
[
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(),
Guid.NewGuid().ToString()
],
SubClass = new()
{
String = Guid.NewGuid().ToString()
}
}
}.ToArray();

primitive.Add.Array(list);

var myList = primitive.Get.Array<Array3Info>();

Assert.NotNull(myList);

for (int i = 0; i < list.Length; i++)
{
Assert.Equal(list[i].Number, myList[i].Number);
Assert.Equal(list[i].String, myList[i].String);
Assert.Equal(list[i].Bool, myList[i].Bool);
Assert.Equal(list[i].List, myList[i].List);
Assert.Equal(list[i].Array, myList[i].Array);
Assert.Equal(list[i].SubClass?.String, myList[i].SubClass?.String);
}

Assert.True(primitive.IsValid);
}

private class Array3Info
{
public int Number { get; set; }
public string? String { get; set; }
public bool Bool { get; set; }
public List<string>? List { get; set; }
public string[]? Array { get; set; }
public Sub? SubClass { get; set; }

public class Sub
{
public string? String { get; set; }
}
}
}

0 comments on commit 1661aa5

Please sign in to comment.