<commit_before>#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import unittest
import random
from matrix import Matrix, addedProduct


class TestAddedProduct(unittest.TestCase):
    def testBasicAddedProduct(self):
        list1 = [1, 2, 3]
        list2 = [2, 4, 6]
        self.assertEqual(28, addedProduct(list1, list2))


class TestBaiscMatrix(unittest.TestCase):
    def test_representation(self):
        columns = 2
        rows = 3
        matrix = Matrix(rows, columns)
        self.assertEqual(matrix.columnCount, 2)
        self.assertEqual(matrix.rowCount, 3)

        for column in range(columns):
            for row in range(rows):
                self.assertEqual(matrix.getValue(column, row), 0)


class TestSettingValues(unittest.TestCase):
    def test_adding_some_values(self):
        columns = 2
        rows = 3
        matrix = Matrix(rows, columns)
        matrix.setValue(2, 1, 2)
        matrix.setValue(3, 2, 6)
        self.assertEqual(2, matrix.getValue(2, 1))
        self.assertEqual(6, matrix.getValue(3, 2))

    def test_adding_columns(self):
        columns = 2
        rows = 3
        matrix = Matrix(rows, columns)
        self.assertRaises(ValueError, matrix.setColumn, 1, [1, 2, 3, 4])
        matrix.setColumn(1, [1, 2, 3])
        matrix.setColumn(2, [4, 5, 6])
        self.assertEqual(matrix.matrix, [[1, 4], [2, 5], [3, 6]])
        self.assertEqual(matrix.getColumn(1), [1, 2, 3])

    def test_adding_rows(self):
        columns = 2
        rows = 3
        matrix = Matrix(rows, columns)
        self.assertRaises(ValueError, matrix.setRow, 1, [1, 2, 3])
        matrix.setRow(2, [2, 5])
        self.assertEqual(matrix.getRow(1), [0, 0])
        self.assertEqual(matrix.getRow(2), [2, 5])


class TestMultiplyingMatrixes(unittest.TestCase):
    def test_multiplying_matrixes(self):
        matrix1 = Matrix(2, 3)
        matrix1.setRow(1, [3, 2, 1])
        matrix1.setRow(2, [1, 0, 2])

        matrix2 = Matrix(3, 2)
        matrix2.setColumn(1, [1, 0, 4])
        matrix2.setColumn(2, [2, 1, 0])

        matrixWithWrongDimension = Matrix(5, 6)

        with self.assertRaises(TypeError):
            matrix2 * matrixWithWrongDimension

        correctMultipliedMatrix = Matrix(2, 2)
        correctMultipliedMatrix.setRow(1, [7, 8])
        correctMultipliedMatrix.setRow(2, [9, 2])
        multipliedMatrix = matrix1 * matrix2
        self.assertEqual(multipliedMatrix.matrix,
                         correctMultipliedMatrix.matrix)

    def test_multiplying_big_matrixes(self):
        #this only tests speed and not correctness
        matrix1 = Matrix(20, 20)
        matrix2 = Matrix(20, 20)
        for i in range(matrix1.rowCount + 1):
            matrix2.setColumn(i, [random.randint(0, 5000) for i in range(20)])
            matrix1.setColumn(i, [random.randint(0, 5000) for i in range(20)])
        multiplied = matrix1 * matrix2
        print(multiplied)


if __name__ == "__main__":
    unittest.main()
<commit_msg>add test for floats in matrix multipllication<commit_after>#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import unittest
import random
from matrix import Matrix, addedProduct


class TestAddedProduct(unittest.TestCase):
    def testBasicAddedProduct(self):
        list1 = [1, 2, 3]
        list2 = [2, 4, 6]
        self.assertEqual(28, addedProduct(list1, list2))


class TestBaiscMatrix(unittest.TestCase):
    def test_representation(self):
        columns = 2
        rows = 3
        matrix = Matrix(rows, columns)
        self.assertEqual(matrix.columnCount, 2)
        self.assertEqual(matrix.rowCount, 3)

        for column in range(columns):
            for row in range(rows):
                self.assertEqual(matrix.getValue(column, row), 0)


class TestSettingValues(unittest.TestCase):
    def test_adding_some_values(self):
        columns = 2
        rows = 3
        matrix = Matrix(rows, columns)
        matrix.setValue(2, 1, 2)
        matrix.setValue(3, 2, 6)
        self.assertEqual(2, matrix.getValue(2, 1))
        self.assertEqual(6, matrix.getValue(3, 2))

    def test_adding_columns(self):
        columns = 2
        rows = 3
        matrix = Matrix(rows, columns)
        self.assertRaises(ValueError, matrix.setColumn, 1, [1, 2, 3, 4])
        matrix.setColumn(1, [1, 2, 3])
        matrix.setColumn(2, [4, 5, 6])
        self.assertEqual(matrix.matrix, [[1, 4], [2, 5], [3, 6]])
        self.assertEqual(matrix.getColumn(1), [1, 2, 3])

    def test_adding_rows(self):
        columns = 2
        rows = 3
        matrix = Matrix(rows, columns)
        self.assertRaises(ValueError, matrix.setRow, 1, [1, 2, 3])
        matrix.setRow(2, [2, 5])
        self.assertEqual(matrix.getRow(1), [0, 0])
        self.assertEqual(matrix.getRow(2), [2, 5])


class TestMultiplyingMatrixes(unittest.TestCase):
    def test_multiplying_matrixes(self):
        matrix1 = Matrix(2, 3)
        matrix1.setRow(1, [3, 2, 1])
        matrix1.setRow(2, [1, 0, 2])

        matrix2 = Matrix(3, 2)
        matrix2.setColumn(1, [1, 0, 4])
        matrix2.setColumn(2, [2, 1, 0])

        matrixWithWrongDimension = Matrix(5, 6)

        with self.assertRaises(TypeError):
            matrix2 * matrixWithWrongDimension

        correctMultipliedMatrix = Matrix(2, 2)
        correctMultipliedMatrix.setRow(1, [7, 8])
        correctMultipliedMatrix.setRow(2, [9, 2])
        multipliedMatrix = matrix1 * matrix2
        self.assertEqual(multipliedMatrix.matrix,
                         correctMultipliedMatrix.matrix)

    def test_multiplying_matrixes_with_floats(self):
        matrix1 = Matrix(2, 3)
        matrix1.setRow(1, [3.5, 2, 1])
        matrix1.setRow(2, [1, 0, 2.5])

        matrix2 = Matrix(3, 2)
        matrix2.setColumn(1, [0.5, 0, 4])
        matrix2.setColumn(2, [2, 1.375, 0])

        correctMultipliedMatrix = Matrix(2, 2)
        correctMultipliedMatrix.setRow(1, [5.75, 9.75])
        correctMultipliedMatrix.setRow(2, [10.5, 2])
        multipliedMatrix = matrix1 * matrix2
        self.assertEqual(multipliedMatrix.matrix,
                         correctMultipliedMatrix.matrix)

    def test_multiplying_big_matrixes(self):
        #this only tests speed and not correctness
        matrix1 = Matrix(20, 20)
        matrix2 = Matrix(20, 20)
        for i in range(matrix1.rowCount + 1):
            matrix2.setColumn(i, [random.randint(0, 5000) for i in range(20)])
            matrix1.setColumn(i, [random.randint(0, 5000) for i in range(20)])
        matrix1 * matrix2

if __name__ == "__main__":
    unittest.main()

{'fraction_non_alphanumeric': 0.12297586312251757, 'fraction_numerical': 0.05071799572257867, 'mean_word_length': 2.489872068230277, 'pattern_counts': {'":': 2, '<': 3, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5473260', 'n_tokens_mistral': 2278, 'n_tokens_neox': 2107, 'n_words': 492}