package org.openlca.core.matrix.format;

import static org.junit.Assert.*;

import org.junit.Test;

public class CopyToTest {

	@Test
	public void testCopyOffset() {

		var source = HashPointMatrix.of(new double[][] {
			{1,1,1,1},
			{1,1,1,1},
			{1,1,1,1}
		});

		for (var rowOffset = 0; rowOffset <= 10; rowOffset++) {
			for (var colOffset = 0; colOffset <= 10; colOffset++) {
				var target = new DenseMatrix(10, 10);
				source.copyTo(target, rowOffset, colOffset);
				// System.out.println(target);

				for (int i = 0; i < 10; i++) {
					for (int j = 0; j < 10; j++) {
						if (i >= rowOffset
							&& i < (rowOffset + source.rows)
							&& j >= colOffset
							&& j < (colOffset + source.cols)) {
							assertEquals(1.0, target.get(i, j), 1e-16);
						}else {
							assertEquals(0.0, target.get(i, j), 1e-16);
						}
					}
				}
			}
		}
	}
}

@@ -45,161 +45,394 @@
 ort 
-static org.junit.Assert.*;%0A%0Aimport org.junit.Test;%0A%0Apublic class CopyToTest %7B%0A%0A%09@Test%0A%09public void testCopyOff
+java.util.ArrayList;%0Aimport java.util.Collection;%0Aimport java.util.List;%0A%0Aimport static org.junit.Assert.*;%0A%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.junit.runners.Parameterized;%0A%0A@RunWith(Parameterized.class)%0Apublic record CopyToTest(MatrixReader source, Matrix target) %7B%0A%0A%09@Parameterized.Parameters%0A%09public static Collection%3CObject%5B%5D%3E 
 set
+up
 () %7B%0A
-%0A
 %09%09var 
-source = HashPointMatrix.of(
+data = 
 new 
@@ -445,17 +445,16 @@
 %5B%5D%5B%5D
- 
 %7B%0A%09%09%09%7B1,
 1,1,
@@ -445,28 +445,31 @@
 %5B%5D%5B%5D%7B%0A%09%09%09%7B1,
+ 
 1,
+ 
 1,
+ 
 1%7D,%0A%09%09%09%7B1,1,
@@ -466,20 +466,23 @@
 ,%0A%09%09%09%7B1,
+ 
 1,
+ 
 1,
+ 
 1%7D,%0A%09%09%09%7B
@@ -487,21 +487,488 @@
 %09%7B1,
+ 
 1,
+ 
 1,
+ 
 1%7D%0A%09%09%7D
-)
 ;%0A
+%0A%09%09var sources = List.of(%0A%09%09%09DenseMatrix.of(data),%0A%09%09%09HashPointMatrix.of(data),%0A%09%09%09CSCMatrix.of(data),%0A%09%09%09JavaMatrix.of(data));%0A%09%09int n = 10;%0A%09%09var targets = List.of(%0A%09%09%09new DenseMatrix(n, n),%0A%09%09%09new HashPointMatrix(n, n),%0A%09%09%09new JavaMatrix(n, n));%0A%09%09var pairs = new ArrayList%3CObject%5B%5D%3E();%0A%09%09for (var source : sources) %7B%0A%09%09%09for (var target : targets) %7B%0A%09%09%09%09pairs.add(new Object%5B%5D%7Bsource, target%7D);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return pairs;%0A%09%7D%0A%0A%09@Test%0A%09public void testCopyOffset() %7B
 %0A%09%09f
@@ -1102,30 +1102,25 @@
 t = 
-new DenseMatrix(10, 10
+this.target.copy(
 );%0A%09
@@ -1171,44 +1171,8 @@
 t);%0A
-%09%09%09%09// System.out.println(target);%0A%0A
 %09%09%09%09
@@ -1301,16 +1301,18 @@
 rce.rows
+()
 )%0A%09%09%09%09%09%09
@@ -1367,17 +1367,22 @@
 urce.col
-s
+umns()
 )) %7B%0A%09%09%09
@@ -1436,16 +1436,17 @@
 %0A%09%09%09%09%09%09%7D
+ 
 else %7B%0A%09

test more matrix types in the copy-to test