// Copyright 2017-2019 Alexander Luzgarev using System.Collections.Generic; using System.Numerics; using NUnit.Framework; namespace MatFileHandler.Tests { /// /// Tests of Matlab array manipulation. /// [TestFixture] public class ArrayHandlingTests { private DataBuilder Builder { get; set; } /// /// Set up a DataBuilder. /// [SetUp] public void Setup() { Builder = new DataBuilder(); } /// /// Test numerical array creation. /// [Test] 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. /// [Test] public void TestNumArray() { var array = Builder.NewArray(2, 3); array[0, 1] = 2; Assert.That(array[0, 1], Is.EqualTo(2)); } /// /// Test cell array manipulation. /// [Test] public void TestCellArray() { var array = Builder.NewCellArray(2, 3); Assert.That(array.Dimensions, Is.EqualTo(new[] { 2, 3 })); array[0, 1] = Builder.NewArray(1, 2); Assert.That(array[1, 2].IsEmpty, Is.True); Assert.That(array[0, 1].IsEmpty, Is.False); var assigned = (IArrayOf)array[0, 1]; Assert.That(assigned, Is.Not.Null); Assert.That(assigned.Dimensions, Is.EqualTo(new[] { 1, 2 })); } /// /// Test structure array manipulation. /// [Test] public void TestStructureArray() { var array = Builder.NewStructureArray(new[] { "x", "y" }, 2, 3); array["x", 0, 1] = Builder.NewArray(1, 2); Assert.That(array["y", 0, 1].IsEmpty, Is.True); Assert.That(array["x", 0, 1].IsEmpty, Is.False); var assigned = (IArrayOf)array["x", 0, 1]; Assert.That(assigned, Is.Not.Null); Assert.That(assigned.Dimensions, Is.EqualTo(new[] { 1, 2 })); } /// /// Test character array manipulation. /// [Test] public void TestString() { var array = Builder.NewCharArray("🍆"); Assert.That(array.Dimensions, Is.EqualTo(new[] { 1, 2 })); } /// /// Test file creation. /// [Test] public void TestFile() { var file = Builder.NewFile(new List()); Assert.That(file, Is.Not.Null); } private static void TestCreateArrayOf() where T : struct { var array = new DataBuilder().NewArray(2, 3); Assert.That(array, Is.Not.Null); } } }