// 3rd_party_lib:matrix4cj/target/matrix4cj
// 3rd_party_lib_ohos:matrix4cj/target/aarch64-linux-ohos/matrix4cj
package matrix4cj.tests.HLT.LEVEL1

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

@Test
public class TestMatrix {
    @TestCase
    func L1_Test_Matrix_copy_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]
            ]
        )
        var result = matrix01.clone()
        var expected_result = 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]
            ]
        )
        @Assert(result.rowNum,expected_result.rowNum)
        @Assert(result.colNum,expected_result.colNum)
        var rows = result.rowNum
        var cols = result.colNum
        for (i in 0..rows) {
            for (j in 0..cols) {
                @Assert(abs(expected_result.get(i,j)-result.get(i,j))<1e-6,true)
            }
        }
    }
    @TestCase
    func L1_Test_Matrix_clone_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]
            ]
        )
        var result = (matrix01.clone() as Matrix).getOrThrow()
        @Assert(result.rowNum,matrix01.rowNum)
        @Assert(result.colNum,matrix01.colNum)
        var rows = result.rowNum
        var cols = result.colNum
        for (i in 0..rows) {
            for (j in 0..cols) {
                @Assert(abs(matrix01.get(i,j)-result.get(i,j))<1e-6,true)
            }
        }
    }
    @TestCase
    func L1_Test_Matrix_constructWithCopy_03(): Unit {
        var array = [[1.0, 2.0, 3.0], [1.0, 2.0, 3.0]]
        var matrix01 = Matrix(array)
        @Assert(matrix01.rowNum,2)
        @Assert(matrix01.colNum,3)
        @Assert(matrix01.get(0,0),1.0)
        @Assert(matrix01.get(0,1),2.0)
        @Assert(matrix01.get(0,2),3.0)
        @Assert(matrix01.get(1,0),1.0)
        @Assert(matrix01.get(1,1),2.0)
        @Assert(matrix01.get(1,2),3.0)
    }
    @TestCase
    func L1_Test_Matrix_det_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]
            ]
        )
        var re = matrix01.det()
        @Assert(re,4.063130600000001)
    }
    @TestCase
    func L1_Test_Matrix_det_02(): Unit {
        var matrix01 = Matrix(
            [
                [0.0, 0.0, 0.0, 0.0],
                [0.0, 0.0, 0.0, 0.0],
                [0.0, 0.0, 0.0, 0.0],
                [0.0, 0.0, 0.0, 0.0]
            ]
        )
        var re = matrix01.det()
        @Assert(re,0.0)
    }
    @TestCase
    func L1_Test_Matrix_det_03(): Unit {
        var matrix01 = Matrix(
            [
                [1.0, 0.0, 0.0, 0.0],
                [0.0, 1.0, 0.0, 0.0],
                [0.0, 0.0, 1.0, 0.0],
                [0.0, 0.0, 0.0, 1.0]
            ]
        )
        var re = matrix01.det()
        @Assert(re,1.0)
    }
}