Accord.Tests.Math.MatReaderTest.ConstructorTest C# (CSharp) Method

ConstructorTest() private method

private ConstructorTest ( ) : void
return void
        public void ConstructorTest()
        {
            MemoryStream file = new MemoryStream(Resources.simplestruct);

            // Create a new MAT file reader
            var reader = new MatReader(file);

            // Extract some basic information about the file:
            string description = reader.Description; // "MATLAB 5.0 MAT-file, Platform: PCWIN"
            int    version     = reader.Version;     // 256
            bool   bigEndian   = reader.BigEndian;   // false


            // Enumerate the fields in the file
            foreach (var field in reader.Fields)
                Console.WriteLine(field.Key); // "structure"

            // We have the single following field
            var structure = reader["structure"];

            // Enumerate the fields in the structure
            foreach (var field in structure.Fields)
                Console.WriteLine(field.Key); // "a", "string"

            // Check the type for the field "a"
            var aType = structure["a"].ValueType; // byte[,]

            // Retrieve the field "a" from the file
            var a = structure["a"].GetValue<byte[,]>();

            // We can also do directly if we know the type in advance
            var s = reader["structure"]["string"].GetValue<string>();


            Assert.AreEqual(typeof(byte[,]), aType);
            Assert.AreEqual(typeof(string), reader["structure"]["string"].ValueType);

            Assert.AreEqual(
                "MATLAB 5.0 MAT-file, Platform: PCWIN, Created on: Thu Feb 22 01:39:50 2007",
                reader.Description);
            Assert.AreEqual(256, reader.Version);
            Assert.IsFalse(reader.BigEndian);

            byte[,] expected = 
            {
                { 1, 2, 3 },
                { 4, 5, 6 },
            };

            Assert.IsTrue(expected.IsEqual(a));
            Assert.AreEqual("ala ma kota", s);
        }