Code editing task: matrix
Topic: Math; change kind: corrective

Original code:
from typing import List


class Matrix:
    def __init__(self, content: List[List[int]]) -> None:
        num_cols = None
        for row in content:
            if num_cols is None:
                num_cols = len(row)
            else:
                if len(row) != num_cols:
                    raise ValueError
        self.content = content

    def transpose(self) -> None:
        new_content = [
            [0 for i in range(len(self.content))] for i in range(len(self.content[0]))
        ]
        for row in range(len(self.content)):
            for col in range(len(self.content[row])):
                new_content[col][row] = self.content[row][col]
        self.content = new_content

    def determinant(self) -> int:
        assert len(self.content) == len(self.content[0])

        if len(self.content) == 2:
            return (
                self.content[0][0] * self.content[1][1]
                - self.content[0][1] * self.content[1][1]
            )
        elif len(self.content) == 3:
            t = self.content
            return (
                t[0][0] * (t[1][1] * t[2][2] - t[1][2] * t[2][1])
                - t[1][0] * (t[0][1] * t[2][2] - t[0][2] * t[2][1])
                + t[2][0] * (t[0][1] * t[1][2] - t[0][2] * t[1][1])
            )
        else:
            raise NotImplementedError

Instruction (descriptive):
the `determinant` method on the `Matrix` class should return the determinant of all 2x2 or 3x3 matrices with determinants which exist. It should throw an AssertionError for matrices that do not have determinants and a NotImplementedError for matrices which are not 2x2 or 3x3.

Instruction (lazy):
the `determinant` method on the Matrix class should return the determinant of the given matrix but it currently does not.

Edited code:
from typing import List


class Matrix:
    def __init__(self, content: List[List[int]]) -> None:
        num_cols = None
        for row in content:
            if num_cols is None:
                num_cols = len(row)
            else:
                if len(row) != num_cols:
                    raise ValueError
        self.content = content

    def transpose(self) -> None:
        new_content = [
            [0 for i in range(len(self.content))] for i in range(len(self.content[0]))
        ]
        for row in range(len(self.content)):
            for col in range(len(self.content[row])):
                new_content[col][row] = self.content[row][col]
        self.content = new_content

    def determinant(self) -> int:
        assert len(self.content) == len(self.content[0])

        if len(self.content) == 2:
            return (
                self.content[0][0] * self.content[1][1]
                - self.content[0][1] * self.content[1][0]
            )
        elif len(self.content) == 3:
            t = self.content
            return (
                t[0][0] * (t[1][1] * t[2][2] - t[1][2] * t[2][1])
                - t[1][0] * (t[0][1] * t[2][2] - t[0][2] * t[2][1])
                + t[2][0] * (t[0][1] * t[1][2] - t[0][2] * t[1][1])
            )
        else:
            raise NotImplementedError

Tests:
### START TESTS ###
if True:  # pragma: no cover
    m = Matrix([[0, 1]])
    m.transpose()
    assert m.content == [[0], [1]]

    m = Matrix([[0, 1], [0, 1]])
    m.transpose()
    assert m.content == [[0, 0], [1, 1]]

    m = Matrix([[0, 2], [0, 1]])
    m.transpose()
    assert m.content == [[0, 0], [2, 1]]

    try:
        Matrix([[1], [2, 2]])
    except ValueError:
        assert True
    else:
        assert False

    try:
        Matrix([[1, 2, 3], [2, 2, 3]]).determinant()
    except AssertionError:
        assert True
    else:
        assert False

    try:
        Matrix([[1]]).determinant()
    except NotImplementedError:
        assert True
    else:
        assert False

    try:
        Matrix([[1], [2]]).determinant()
    except AssertionError:
        assert True
    else:
        assert False

    m = Matrix([[0, 2], [0, 1]])
    assert m.determinant() == 0

    m = Matrix([[2, 2], [0, 1]])
    assert m.determinant() == 2

    m = Matrix([[2, -1], [3, 1]])
    assert m.determinant() == 5

    m = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    assert m.determinant() == 0
    m = Matrix([[1, 2, 3], [4, -5, 6], [7, -8, 9]])
    assert m.determinant() == 24
    m = Matrix([[5, 5, 5], [4, 5, 6], [7, 8, 9]])
    assert m.determinant() == 0
    m = Matrix([[1, 9, 3], [4, -5, 9], [7, -8, 9]])
    assert m.determinant() == 279