// 3rd_party_lib:matrix4cj/target/matrix4cj
// 3rd_party_lib_ohos:matrix4cj/target/aarch64-linux-ohos/matrix4cj

package matrix4cj.tests.HLT.LEVEL2

import matrix4cj.*
import std.math.*
import std.unittest.*
import std.unittest.testmacro.*

@Test
public class TestMatrix2 {
    @TestCase
    func L2_Test_Matrix_constructWithCopy_01(): Unit {
        var array = Array<Array<Float64>>()
        try {
            Matrix(array)
            @Assert(false)
        } catch (e: IllegalArgumentException) {
            if (e.toString().contains("cannot create Matrix from empty array")) {
                @Assert(true)
            } else {
                @Assert(false)
            }
        }
    }
    @TestCase
    func L2_Test_Matrix_constructWithCopy_02(): Unit {
        var array = [
            [1.0, 2.0, 3.0],
            [1.0, 2.0],
            [1.0]
        ]
        try {
            Matrix(array)
            @Assert(false)
        } catch (e: IllegalArgumentException) {
            if (e.toString().contains("Expected a consistent row lengths 2D array with")) {
                @Assert(true)
            } else {
                @Assert(false)
            }
        }
    }
    @TestCase
    func L2_Test_Matrix_get_01(): Unit {
        var matrix01 = Matrix(
            [
                [1.80, 2.88, 2.05, -0.89],
                [5.25, -2.95, -0.95, -3.80],
                [1.58, -2.69, -2.90, -1.04],
                [-1.11, -0.66, -0.59, 0.80]
            ]
        )
        try {
            matrix01.get(-1, 1)
            @Assert(false)
        } catch (e: IndexOutOfBoundsException) {
            @Assert(true)
        }
    }
    @TestCase
    func L2_Test_Matrix_get_02(): Unit {
        var matrix01 = Matrix(
            [
                [1.80, 2.88, 2.05, -0.89],
                [5.25, -2.95, -0.95, -3.80],
                [1.58, -2.69, -2.90, -1.04],
                [-1.11, -0.66, -0.59, 0.80]
            ]
        )
        try {
            matrix01.get(0, 4)
            @Assert(false)
        } catch (e: IndexOutOfBoundsException) {
            @Assert(true)
        }
    }
    @TestCase
    func L2_Test_Matrix_identity_04(): Unit {
        var rows = -1
        var cols = 3
        try {
            Matrix.Identity(rows, cols)
            @Assert(false)
        } catch (e: IllegalArgumentException) {
            @Assert(true)
        }
    }
    @TestCase
    func L2_Test_Matrix_identity_05(): Unit {
        var rows = 1
        var cols = -1
        try {
            Matrix.Identity(rows, cols)
            @Assert(false)
        } catch (e: IllegalArgumentException) {
            @Assert(true)
        }
    }
    @TestCase
    func L2_Test_Matrix_Init01_02(): Unit {
        var rows = -4
        var cols = 5
        try {
            Matrix(rows, cols)
            @Assert(false)
        } catch (e: IllegalArgumentException) {
            @Assert(true)
        }
    }
    @TestCase
    func L2_Test_Matrix_Init01_03(): Unit {
        var rows = 4
        var cols = -5
        try {
            Matrix(rows, cols)
            @Assert(false)
        } catch (e: IllegalArgumentException) {
            @Assert(true)
        }
    }
    @TestCase
    func L2_Test_Matrix_Init02_02(): Unit {
        var rows = -4
        var cols = 5
        try {
            Matrix(rows, cols)
            @Assert(false)
        } catch (e: IllegalArgumentException) {
            @Assert(true)
        }
    }
    @TestCase
    func L2_Test_Matrix_Init02_03(): Unit {
        var rows = 4
        var cols = -5
        try {
            Matrix(rows, cols)
            @Assert(false)
        } catch (e: IllegalArgumentException) {
            @Assert(true)
        }
    }
    @TestCase
    func L2_Test_Matrix_Init03_01(): Unit {
        var array = Array<Array<Float64>>()
        try {
            Matrix(array)
            @Assert(false)
        } catch (e: IllegalArgumentException) {
            if (e.toString().contains("cannot create Matrix from empty array")) {
                @Assert(true)
            } else {
                @Assert(false)
            }
        }
    }
    @TestCase
    func L2_Test_Matrix_Init04_02(): Unit {
        var array: Array<Array<Float64>> = [[1.0], [2.0], [3.0]]
        var matrix01 = Matrix(array)
        try {
            matrix01.get(3, 0)
            @Assert(false)
        } catch (e: IndexOutOfBoundsException) {
            @Assert(true)
        }
        try {
            matrix01.get(0, 1)
            @Assert(false)
        } catch (e: IndexOutOfBoundsException) {
            @Assert(true)
        }
    }
    @TestCase
    func L2_Test_Matrix_Init04_03(): Unit {
        var array = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]
        var matrix01 = Matrix(array)
        try {
            matrix01.get(3, 0)
            @Assert(false)
        } catch (e: IndexOutOfBoundsException) {
            @Assert(true)
        }
    }
    @TestCase
    func L2_Test_Matrix_Init05_03(): Unit {
        var array: Array<Float64> = [1.0, 2.0, 3.0]
        try {
            Matrix(array, rowNum: 2)
            @Assert(false)
        } catch (e: IllegalArgumentException) {
            if (e.toString().contains("Expected a 1D array with size=2, but got size=3")) {
                @Assert(true)
            } else {
                @Assert(false)
            }
        }
    }
    @TestCase
    func L2_Test_Matrix_Init05_04(): Unit {
        var array = [1.0, 2.0]
        var matrix01 = Matrix(array, rowNum: 1)
        @Assert(matrix01.rowNum,1)
        @Assert(matrix01.colNum,2)
        try {
            matrix01.get(1, 0)
            @Assert(false)
        } catch (e: IndexOutOfBoundsException) {
            @Assert(true)
        }
    }
}