// 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 TestMatrix9 {
    @TestCase
    func L0_Test_Matrix_setMatrix01_01(): Unit {
        var matrix02 = Matrix([[8.80, 8.88], [8.25, -8.95]])
        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[0..2, 2..0] = matrix02
            @Assert(false)
        }
        catch (e: IllegalArgumentException) {
            if (e.toString().contains("Invalid range for block extraction.")) {
                @Assert(true)
            } else {
                @Assert(false)
            }
        }
    }
    @TestCase
    func L0_Test_Matrix_setMatrix01_02(): Unit {
        var matrix02 = Matrix([[8.80, 8.88], [8.25, -8.95]])
        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]
            ]
        )
        matrix01[0..2, 2..=3] = matrix02
        var expected_matrix = Matrix(
            [
                [1.80, 2.88, 8.8, 8.88],
                [5.25, -2.95, 8.25, -8.95],
                [1.58, -2.69, -2.90, -1.04],
                [-1.11, -0.66, -0.59, 0.80]
            ]
        )
        @Assert(matrix01.rowNum,expected_matrix.rowNum)
        @Assert(matrix01.colNum,expected_matrix.colNum)
        var rows = matrix01.rowNum
        var cols = matrix01.colNum
        for (i in 0..rows) {
            for (j in 0..cols) {
                @Assert(abs(expected_matrix.get(i,j)-matrix01.get(i,j))<1e-6,true)
            }
        }
    }
    @TestCase
    func L0_Test_Matrix_setMatrix02_01(): Unit {
        var matrix02 = Matrix([[8.80, 8.88], [8.25, -8.95]])
        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]
            ]
        )
        matrix01[[0, 2], [2, 0]] = matrix02
        var expected_matrix = Matrix(
            [
                [8.88, 2.88, 8.8, -0.89],
                [5.25, -2.95, -0.95, -3.80],
                [-8.95, -2.69, 8.25, -1.04],
                [-1.11, -0.66, -0.59, 0.80]
            ]
        )
        @Assert(matrix01.rowNum,expected_matrix.rowNum)
        @Assert(matrix01.colNum,expected_matrix.colNum)
        var rows = matrix01.rowNum
        var cols = matrix01.colNum
        for (i in 0..rows) {
            for (j in 0..cols) {
                @Assert(abs(expected_matrix.get(i,j)-matrix01.get(i,j))<1e-6,true)
            }
        }
    }
    @TestCase
    func L0_Test_Matrix_setMatrix02_02(): Unit {
        var matrix02 = Matrix([[8.80, 8.88], [8.25, -8.95]])
        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]
            ]
        )
        matrix01[[0, 1], [2, 3]] = matrix02
        var expected_matrix = Matrix(
            [
                [1.80, 2.88, 8.8, 8.88],
                [5.25, -2.95, 8.25, -8.95],
                [1.58, -2.69, -2.90, -1.04],
                [-1.11, -0.66, -0.59, 0.80]
            ]
        )
        @Assert(matrix01.rowNum,expected_matrix.rowNum)
        @Assert(matrix01.colNum,expected_matrix.colNum)
        var rows = matrix01.rowNum
        var cols = matrix01.colNum
        for (i in 0..rows) {
            for (j in 0..cols) {
                @Assert(abs(expected_matrix.get(i,j)-matrix01.get(i,j))<1e-6,true)
            }
        }
    }
    @TestCase
    func L0_Test_Matrix_setMatrix03_01(): Unit {
        var matrix02 = Matrix([[8.80, 8.88], [8.25, -8.95]])
        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[[0, 2], 2..0] = matrix02
            @Assert(false)
        }
        catch (e: IllegalArgumentException) {
            if (e.toString().contains("Value matrix dimensions must match the specified row indices and column range.")) {
                @Assert(true)
            } else {
                @Assert(false)
            }
        }
    }
    @TestCase
    func L0_Test_Matrix_setMatrix03_02(): Unit {
        var matrix02 = Matrix([[8.80, 8.88], [8.25, -8.95]])
        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]
            ]
        )
        matrix01[[0, 1], 2..4] = matrix02
        var expected_matrix = Matrix(
            [
                [1.80, 2.88, 8.8, 8.88],
                [5.25, -2.95, 8.25, -8.95],
                [1.58, -2.69, -2.90, -1.04],
                [-1.11, -0.66, -0.59, 0.80]
            ]
        )
        @Assert(matrix01.rowNum,expected_matrix.rowNum)
        @Assert(matrix01.colNum,expected_matrix.colNum)
        var rows = matrix01.rowNum
        var cols = matrix01.colNum
        for (i in 0..rows) {
            for (j in 0..cols) {
                @Assert(abs(expected_matrix.get(i,j)-matrix01.get(i,j))<1e-6,true)
            }
        }
    }
    @TestCase
    func L0_Test_Matrix_setMatrix04_02(): Unit {
        var matrix02 = Matrix([[8.80, 8.88], [8.25, -8.95]])
        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]
            ]
        )
        matrix01[0..2, [2, 3]] = matrix02
        var expected_matrix = Matrix(
            [
                [1.80, 2.88, 8.8, 8.88],
                [5.25, -2.95, 8.25, -8.95],
                [1.58, -2.69, -2.90, -1.04],
                [-1.11, -0.66, -0.59, 0.80]
            ]
        )
        @Assert(matrix01.rowNum,expected_matrix.rowNum)
        @Assert(matrix01.colNum,expected_matrix.colNum)
        var rows = matrix01.rowNum
        var cols = matrix01.colNum
        for (i in 0..rows) {
            for (j in 0..cols) {
                @Assert(abs(expected_matrix.get(i,j)-matrix01.get(i,j))<1e-6,true)
            }
        }
    }
}