<commit_before>package com.unidev.lib.matrix;

import org.junit.Test;

import static com.unidev.lib.matrix.model.Coordinate.coordinate;
import static com.unidev.lib.matrix.model.Coordinate.newInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.IsNot.not;

public class TestMatrix {

    @Test
    public void testMatrixCreation() {

        DemoMatrix demoMatrix = new DemoMatrix(3);

        assertThat(demoMatrix.getRows(), is(3));
        assertThat(demoMatrix.getColumns(), is(3));

        demoMatrix = new DemoMatrix(4, 5);

        assertThat(demoMatrix.getRows(), is(4));
        assertThat(demoMatrix.getColumns(), is(5));

    }

    @Test
    public void testElementGetSet() {
        DemoMatrix demoMatrix = new DemoMatrix(3);

        demoMatrix.set(newInstance().withRow(0).withColumn(1), 666);

        Integer value = demoMatrix.get(newInstance().withRow(0).withColumn(1));
        assertThat(value, is(666));
    }

    @Test
    public void testMatrixComparasion() {
        DemoMatrix matrix = new DemoMatrix(3);
        DemoMatrix equalMatrix = new DemoMatrix(3);
        DemoMatrix differentSizeMatrix = new DemoMatrix(5,2);

        assertThat(matrix, equalTo(equalMatrix));
        assertThat(matrix, not(equalTo(differentSizeMatrix)));

        DemoMatrix equalSizeDifferentElement = new DemoMatrix(3);
        equalSizeDifferentElement.set(newInstance().withRow(1).withColumn(2), 120);

        assertThat(matrix, not(equalTo(equalSizeDifferentElement)));

    }

    @Test
    public void testMatrixClear() {
        DemoMatrix nullMatrix = new DemoMatrix(3);
        DemoMatrix dataMatrix = new DemoMatrix(3);

        dataMatrix.set(coordinate().withRow(2).withColumn(0), 400);
        assertThat(dataMatrix.get(coordinate().withRow(2).withColumn(0)), is(400));

        dataMatrix.clear();

        assertThat(dataMatrix.get(coordinate().withRow(2).withColumn(0)), is(nullValue()));

        assertThat(dataMatrix, equalTo(nullMatrix));
    }


}<commit_msg>added basic test for matrix shuffle<commit_after>package com.unidev.lib.matrix;

import com.unidev.lib.matrix.utils.MatrixUtils;
import org.junit.Test;

import java.util.Random;

import static com.unidev.lib.matrix.model.Coordinate.coordinate;
import static com.unidev.lib.matrix.model.Coordinate.newInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.core.IsNot.not;

public class TestMatrix {

    @Test
    public void testMatrixCreation() {

        DemoMatrix demoMatrix = new DemoMatrix(3);

        assertThat(demoMatrix.getRows(), is(3));
        assertThat(demoMatrix.getColumns(), is(3));

        demoMatrix = new DemoMatrix(4, 5);

        assertThat(demoMatrix.getRows(), is(4));
        assertThat(demoMatrix.getColumns(), is(5));

    }

    @Test
    public void testElementGetSet() {
        DemoMatrix demoMatrix = new DemoMatrix(3);

        demoMatrix.set(newInstance().withRow(0).withColumn(1), 666);

        Integer value = demoMatrix.get(newInstance().withRow(0).withColumn(1));
        assertThat(value, is(666));
    }

    @Test
    public void testMatrixComparasion() {
        DemoMatrix matrix = new DemoMatrix(3);
        DemoMatrix equalMatrix = new DemoMatrix(3);
        DemoMatrix differentSizeMatrix = new DemoMatrix(5,2);

        assertThat(matrix, equalTo(equalMatrix));
        assertThat(matrix, not(equalTo(differentSizeMatrix)));

        DemoMatrix equalSizeDifferentElement = new DemoMatrix(3);
        equalSizeDifferentElement.set(newInstance().withRow(1).withColumn(2), 120);

        assertThat(matrix, not(equalTo(equalSizeDifferentElement)));

    }

    @Test
    public void testMatrixClear() {
        DemoMatrix nullMatrix = new DemoMatrix(3);
        DemoMatrix dataMatrix = new DemoMatrix(3);

        dataMatrix.set(coordinate().withRow(2).withColumn(0), 400);
        assertThat(dataMatrix.get(coordinate().withRow(2).withColumn(0)), is(400));

        dataMatrix.clear();

        assertThat(dataMatrix.get(coordinate().withRow(2).withColumn(0)), is(nullValue()));

        assertThat(dataMatrix, equalTo(nullMatrix));
    }

    @Test
    public void testMatrixShuffle() {
        DemoMatrix matrix = new DemoMatrix(3);
        Random random = new Random();

        for(Integer row  = 0;row < 3;row++) {
            for(Integer column  = 0;column < 3;column++) {
                matrix.set(coordinate().withRow(row).withColumn(column), random.nextInt());
            }
        }
        DemoMatrix copyMatrix = new DemoMatrix(matrix);
        assertThat(matrix.equals(copyMatrix), is(true));

        MatrixUtils.shuffle(copyMatrix);
        assertThat(matrix.equals(copyMatrix), is(false));

    }



}
{'fraction_non_alphanumeric': 0.12554562461026814, 'fraction_numerical': 0.018499272500519644, 'mean_word_length': 3.430939226519337, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2556920', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1388, 'n_words': 252}