// Copyright 2017-2018 Alexander Luzgarev using System; using System.Collections.Generic; using System.Numerics; using Xunit; namespace MatFileHandler.Tests { /// /// Tests of Matlab array manipulation. /// public sealed class ArrayHandlingTests : IDisposable { /// /// Setup for array handling tests. /// public ArrayHandlingTests() { Builder = new DataBuilder(); } private DataBuilder Builder { get; set; } /// /// Test numerical array creation. /// [Fact] public void TestCreate() { TestCreateArrayOf(); TestCreateArrayOf>(); TestCreateArrayOf(); TestCreateArrayOf>(); TestCreateArrayOf(); TestCreateArrayOf>(); TestCreateArrayOf(); TestCreateArrayOf>(); TestCreateArrayOf(); TestCreateArrayOf>(); TestCreateArrayOf(); TestCreateArrayOf>(); TestCreateArrayOf(); TestCreateArrayOf>(); TestCreateArrayOf(); TestCreateArrayOf>(); TestCreateArrayOf(); TestCreateArrayOf>(); TestCreateArrayOf(); TestCreateArrayOf(); } /// /// Test numerical array manipulation. /// [Fact] public void TestNumArray() { var array = Builder.NewArray(2, 3); array[0, 1] = 2; Assert.Equal(2, array[0, 1]); } /// /// Test cell array manipulation. /// [Fact] public void TestCellArray() { var array = Builder.NewCellArray(2, 3); Assert.Equal(new[] { 2, 3 }, array.Dimensions); array[0, 1] = Builder.NewArray(1, 2); Assert.True(array[1, 2].IsEmpty); Assert.False(array[0, 1].IsEmpty); var assigned = (IArrayOf)array[0, 1]; Assert.NotNull(assigned); Assert.Equal(new[] { 1, 2 }, assigned.Dimensions); } /// /// Test structure array manipulation. /// [Fact] public void TestStructureArray() { var array = Builder.NewStructureArray(new[] { "x", "y" }, 2, 3); array["x", 0, 1] = Builder.NewArray(1, 2); Assert.True(array["y", 0, 1].IsEmpty); Assert.False(array["x", 0, 1].IsEmpty); var assigned = (IArrayOf)array["x", 0, 1]; Assert.NotNull(assigned); Assert.Equal(new[] { 1, 2 }, assigned.Dimensions); } /// /// Test character array manipulation. /// [Fact] public void TestString() { var array = Builder.NewCharArray("🍆"); Assert.Equal(new[] { 1, 2 }, array.Dimensions); } /// /// Test file creation. /// [Fact] public void TestFile() { var file = Builder.NewFile(new List()); Assert.NotNull(file); } private static void TestCreateArrayOf() where T : struct { var array = new DataBuilder().NewArray(2, 3); Assert.NotNull(array); } /// /// Cleanup. /// public void Dispose() { } } }