Kumite (ko͞omiˌtā) is the practice of taking techniques learned from Kata and applying them through the act of freestyle sparring.
You can create a new kumite by providing some initial code and optionally some test cases. From there other warriors can spar with you, by enhancing, refactoring and translating your code. There is no limit to how many warriors you can spar with.
A great use for kumite is to begin an idea for a kata as one. You can collaborate with other code warriors until you have it right, then you can convert it to a kata.
Translation to Python??
def other_angle(a, b): req_angle = 180 - (a + b) return req_angle
fn other_angle(a: u32, b: u32) -> u32 {180 - (a + b)}- def other_angle(a, b):
- req_angle = 180 - (a + b)
- return req_angle
import codewars_test as test @test.describe("tests") def fixed_tests(): @test.it('test cases') def basic_test_cases(): test.assert_equals(other_angle(30, 60), 90) test.assert_equals(other_angle(60, 60), 60) test.assert_equals(other_angle(43, 78), 59) test.assert_equals(other_angle(10, 20), 150) test.assert_equals(other_angle(110, 30), 40) test.assert_equals(other_angle(100, 40), 40)
#[test]fn test() {assert_eq!(other_angle(30, 60), 90);assert_eq!(other_angle(60, 60), 60);assert_eq!(other_angle(43, 78), 59);assert_eq!(other_angle(10, 20), 150);}- import codewars_test as test
- @test.describe("tests")
- def fixed_tests():
- @test.it('test cases')
- def basic_test_cases():
- test.assert_equals(other_angle(30, 60), 90)
- test.assert_equals(other_angle(60, 60), 60)
- test.assert_equals(other_angle(43, 78), 59)
- test.assert_equals(other_angle(10, 20), 150)
- test.assert_equals(other_angle(110, 30), 40)
- test.assert_equals(other_angle(100, 40), 40)
fn parse_quaternion(quaternion: &str) -> [f64; 4] { let mut iter = quaternion.chars().filter(|&c| c != ' ').peekable(); let mut terms = Vec::new(); while let Some(first) = iter.next() { let mut term = first.to_string(); while iter.peek().map_or(false, |&c| !"+-".contains(c)) { term.push(iter.next().unwrap()); } terms.push(term); } let mut real = 0.0; let mut imaginary = 0.0; let mut jmaginary = 0.0; let mut kmaginary = 0.0; for term in terms { match term.chars().last().unwrap() { 'i' => imaginary += parse_term(&term), 'j' => jmaginary += parse_term(&term), 'k' => kmaginary += parse_term(&term), _ => real += parse_term(&term) } } [real, imaginary, jmaginary, kmaginary] } fn parse_term(mut term: &str) -> f64 { if term.chars().last().map_or(false, |c| c.is_ascii_alphabetic()) { term = &term[..term.len()-1]; if !term.chars().any(|c| c.is_ascii_digit()) { return format!("{term}1").parse().unwrap(); } } term.parse().unwrap() }
#include <array>#include <string>#include <regex>#include <algorithm>std::array<float, 4> ParseQuaternion(const std::string& t_quaternion){std::smatch matches;std::regex realCompPattern("(-?)([0-9.]+)*[^ijk]([+]|-|$)");std::regex_search(t_quaternion, matches, realCompPattern);float w = matches.empty() ? 0 : std::stof(matches[0]);auto g = [&](const std::string& t_letter) -> float {const std::regex pattern(R"((-?)([ (0-9).]+)?)" + t_letter);std::string result;if (std::regex_search(t_quaternion, matches, pattern)){if (matches[2].matched && matches[2] != " "){auto matchStr = matches[2].str();matchStr.erase(std::remove(matchStr.begin(), matchStr.end(), ' '), matchStr.end());result = matches[1].str() + matchStr;}else{result = matches[1].str() + "1";}- fn parse_quaternion(quaternion: &str) -> [f64; 4] {
- let mut iter = quaternion.chars().filter(|&c| c != ' ').peekable();
- let mut terms = Vec::new();
- while let Some(first) = iter.next() {
- let mut term = first.to_string();
- while iter.peek().map_or(false, |&c| !"+-".contains(c)) {
- term.push(iter.next().unwrap());
- }
else{result = "0";- terms.push(term);
- }
- let mut real = 0.0;
- let mut imaginary = 0.0;
- let mut jmaginary = 0.0;
- let mut kmaginary = 0.0;
- for term in terms {
- match term.chars().last().unwrap() {
- 'i' => imaginary += parse_term(&term),
- 'j' => jmaginary += parse_term(&term),
- 'k' => kmaginary += parse_term(&term),
- _ => real += parse_term(&term)
- }
return std::stof(result);};- }
- [real, imaginary, jmaginary, kmaginary]
- }
auto i = g("i");auto j = g("j");auto k = g("k");return { w, i, j, k };- fn parse_term(mut term: &str) -> f64 {
- if term.chars().last().map_or(false, |c| c.is_ascii_alphabetic()) {
- term = &term[..term.len()-1];
- if !term.chars().any(|c| c.is_ascii_digit()) {
- return format!("{term}1").parse().unwrap();
- }
- }
- term.parse().unwrap()
- }
#[test] fn test() { assert_eq!(parse_quaternion("1 + 2i + 3j + 4k"),[ 1.0, 2.0, 3.0, 4.0]); assert_eq!(parse_quaternion("-1 + 3i -3j+7k"), [ -1.0, 3.0, -3.0, 7.0]); assert_eq!(parse_quaternion("-1-4i-9j-2k"), [ -1.0, -4.0, -9.0, -2.0]); assert_eq!(parse_quaternion("17-16i-15j-14k"), [ 17.0, -16.0, -15.0, -14.0]); assert_eq!(parse_quaternion("7+2i"), [ 7.0, 2.0, 0.0, 0.0]); assert_eq!(parse_quaternion("2i-6k"), [ 0.0, 2.0, 0.0, -6.0]); assert_eq!(parse_quaternion("1-5j+2k"), [ 1.0, 0.0, -5.0, 2.0]); assert_eq!(parse_quaternion("3+4i-9k"), [ 3.0, 4.0, 0.0, -9.0]); assert_eq!(parse_quaternion("42i+j-k"), [ 0.0, 42.0, 1.0, -1.0]); assert_eq!(parse_quaternion("6-2i+j-3k"), [ 6.0, -2.0, 1.0, -3.0]); assert_eq!(parse_quaternion("1+i+j+k"), [ 1.0, 1.0, 1.0, 1.0]); assert_eq!(parse_quaternion("-1-i-j-k"), [ -1.0, -1.0, -1.0, -1.0]); assert_eq!(parse_quaternion("16k-20j+2i-7"), [ -7.0, 2.0, -20.0, 16.0]); assert_eq!(parse_quaternion("i+4k-3j+2"), [ 2.0, 1.0, -3.0, 4.0]); assert_eq!(parse_quaternion("5k-2i+9+3j"), [ 9.0, -2.0, 3.0, 5.0]); assert_eq!(parse_quaternion("5k-2j+3"), [ 3.0, 0.0, -2.0, 5.0]); assert_eq!(parse_quaternion("1.75-1.75i-1.75j-1.75k"), [1.75, -1.75, -1.75, -1.75]); assert_eq!(parse_quaternion("2.0j-3k+0.47i-13"),[-13.0, 0.47, 2.0, -3.0]); assert_eq!(parse_quaternion("5.6-3i"), [ 5.6, -3.0, 0.0, 0.0]); assert_eq!(parse_quaternion("k-7.6i"), [ 0.0, -7.6, 0.0, 1.0]); assert_eq!(parse_quaternion("0"), [ 0.0, 0.0, 0.0, 0.0]); assert_eq!(parse_quaternion("0j+0k"), [ 0.0, 0.0, 0.0, 0.0]); assert_eq!(parse_quaternion("-0j"), [ 0.0, 0.0, 0.0, 0.0]); assert_eq!(parse_quaternion("1-0k"), [ 1.0, 0.0, 0.0, 0.0]); }
// TODO: Replace examples and use TDD by writing your own testsDescribe(Quaternions){It(AllTests){Assert::That(ParseQuaternion("1 + 2i + 3j + 4k"), Equals(std::array<float, 4>{1, 2, 3, 4}));Assert::That(ParseQuaternion("-1 + 3i -3j+7k"), Equals(std::array<float, 4>{-1, 3, -3, 7}));Assert::That(ParseQuaternion("-1-4i-9j-2k"), Equals(std::array<float, 4>{-1, -4, -9, -2}));Assert::That(ParseQuaternion("17-16i-15j-14k"), Equals(std::array<float, 4>{17, -16, -15, -14}));Assert::That(ParseQuaternion("7+2i"), Equals(std::array<float, 4>{7, 2, 0, 0}));Assert::That(ParseQuaternion("2i-6k"), Equals(std::array<float, 4>{0, 2, 0, -6}));Assert::That(ParseQuaternion("1-5j+2k"), Equals(std::array<float, 4>{1, 0, -5, 2}));Assert::That(ParseQuaternion("3+4i-9k"), Equals(std::array<float, 4>{3, 4, 0, -9}));Assert::That(ParseQuaternion("42i+j-k"), Equals(std::array<float, 4>{0, 42, 1, -1}));Assert::That(ParseQuaternion("6-2i+j-3k"), Equals(std::array<float, 4>{6, -2, 1, -3}));Assert::That(ParseQuaternion("1+i+j+k"), Equals(std::array<float, 4>{1, 1, 1, 1}));Assert::That(ParseQuaternion("-1-i-j-k"), Equals(std::array<float, 4>{-1, -1, -1, -1}));Assert::That(ParseQuaternion("16k-20j+2i-7"), Equals(std::array<float, 4>{-7, 2, -20, 16}));Assert::That(ParseQuaternion("i+4k-3j+2"), Equals(std::array<float, 4>{2, 1, -3, 4}));Assert::That(ParseQuaternion("5k-2i+9+3j"), Equals(std::array<float, 4>{9, -2, 3, 5}));Assert::That(ParseQuaternion("5k-2j+3"), Equals(std::array<float, 4>{3, 0, -2, 5}));Assert::That(ParseQuaternion("1.75-1.75i-1.75j-1.75k"), Equals(std::array<float, 4>{1.75, -1.75, -1.75, -1.75}));Assert::That(ParseQuaternion("2.0j-3k+0.47i-13"), Equals(std::array<float, 4>{-13, 0.47, 2.0, -3}));Assert::That(ParseQuaternion("5.6-3i"), Equals(std::array<float, 4>{5.6, -3, 0, 0}));Assert::That(ParseQuaternion("k-7.6i"), Equals(std::array<float, 4>{0, -7.6, 0, 1}));Assert::That(ParseQuaternion("0"), Equals(std::array<float, 4>{0, 0, 0, 0}));Assert::That(ParseQuaternion("0j+0k"), Equals(std::array<float, 4>{0, 0, 0, 0}));Assert::That(ParseQuaternion("-0j"), Equals(std::array<float, 4>{0, 0, 0, 0}));Assert::That(ParseQuaternion("1-0k"), Equals(std::array<float, 4>{1, 0, 0, 0}));}};- #[test]
- fn test() {
- assert_eq!(parse_quaternion("1 + 2i + 3j + 4k"),[ 1.0, 2.0, 3.0, 4.0]);
- assert_eq!(parse_quaternion("-1 + 3i -3j+7k"), [ -1.0, 3.0, -3.0, 7.0]);
- assert_eq!(parse_quaternion("-1-4i-9j-2k"), [ -1.0, -4.0, -9.0, -2.0]);
- assert_eq!(parse_quaternion("17-16i-15j-14k"), [ 17.0, -16.0, -15.0, -14.0]);
- assert_eq!(parse_quaternion("7+2i"), [ 7.0, 2.0, 0.0, 0.0]);
- assert_eq!(parse_quaternion("2i-6k"), [ 0.0, 2.0, 0.0, -6.0]);
- assert_eq!(parse_quaternion("1-5j+2k"), [ 1.0, 0.0, -5.0, 2.0]);
- assert_eq!(parse_quaternion("3+4i-9k"), [ 3.0, 4.0, 0.0, -9.0]);
- assert_eq!(parse_quaternion("42i+j-k"), [ 0.0, 42.0, 1.0, -1.0]);
- assert_eq!(parse_quaternion("6-2i+j-3k"), [ 6.0, -2.0, 1.0, -3.0]);
- assert_eq!(parse_quaternion("1+i+j+k"), [ 1.0, 1.0, 1.0, 1.0]);
- assert_eq!(parse_quaternion("-1-i-j-k"), [ -1.0, -1.0, -1.0, -1.0]);
- assert_eq!(parse_quaternion("16k-20j+2i-7"), [ -7.0, 2.0, -20.0, 16.0]);
- assert_eq!(parse_quaternion("i+4k-3j+2"), [ 2.0, 1.0, -3.0, 4.0]);
- assert_eq!(parse_quaternion("5k-2i+9+3j"), [ 9.0, -2.0, 3.0, 5.0]);
- assert_eq!(parse_quaternion("5k-2j+3"), [ 3.0, 0.0, -2.0, 5.0]);
- assert_eq!(parse_quaternion("1.75-1.75i-1.75j-1.75k"), [1.75, -1.75, -1.75, -1.75]);
- assert_eq!(parse_quaternion("2.0j-3k+0.47i-13"),[-13.0, 0.47, 2.0, -3.0]);
- assert_eq!(parse_quaternion("5.6-3i"), [ 5.6, -3.0, 0.0, 0.0]);
- assert_eq!(parse_quaternion("k-7.6i"), [ 0.0, -7.6, 0.0, 1.0]);
- assert_eq!(parse_quaternion("0"), [ 0.0, 0.0, 0.0, 0.0]);
- assert_eq!(parse_quaternion("0j+0k"), [ 0.0, 0.0, 0.0, 0.0]);
- assert_eq!(parse_quaternion("-0j"), [ 0.0, 0.0, 0.0, 0.0]);
- assert_eq!(parse_quaternion("1-0k"), [ 1.0, 0.0, 0.0, 0.0]);
- }
def max_sequence(arr): # Code to find maximum sum of subarray l_a = len(arr) sum_b = sum(arr) for i in range(l_a): for k in range(l_a-i+1): sum_c = sum(arr[k:k+i]) if sum_c > sum_b: sum_b = sum_c return(sum_b)
- def max_sequence(arr):
- # Code to find maximum sum of subarray
- l_a = len(arr)
counter = 0for m in arr:if m < 0:counter = counterelse:counter += 1if counter == 0:return(0)- sum_b = sum(arr)
- for i in range(l_a):
if i == 0:sum_b = sum(arr)else:for k in range(l_a-i+1):sum_c = sum(arr[k:k+i])if sum_c > sum_b: sum_b = sum_c- for k in range(l_a-i+1):
- sum_c = sum(arr[k:k+i])
- if sum_c > sum_b: sum_b = sum_c
- return(sum_b)
import codewars_test as test from solution import max_sequence @test.describe("Max Sequence Tests") def test_group(): @test.it("Case 1") def test_case_1(): test.assert_equals(max_sequence([0,1,2,3,4,5,6,7,8,9,10]), 55) test.assert_equals(max_sequence([-22,1,2,3,4,5,6,7,8,9,10]), 55) test.assert_equals(max_sequence([0,1,2,3,4,5,-6,7,8,9,10]), 43) test.assert_equals(max_sequence([0,0,0,0,0,0,0,0,0,99,-1, 23, 43]), 164) test.assert_equals(max_sequence([0] * 10), 0) test.assert_equals(max_sequence([-1] * 10), 0) test.assert_equals(max_sequence([1] * 10), 10)
- import codewars_test as test
- from solution import max_sequence
- @test.describe("Max Sequence Tests")
- def test_group():
- @test.it("Case 1")
- def test_case_1():
- test.assert_equals(max_sequence([0,1,2,3,4,5,6,7,8,9,10]), 55)
- test.assert_equals(max_sequence([-22,1,2,3,4,5,6,7,8,9,10]), 55)
- test.assert_equals(max_sequence([0,1,2,3,4,5,-6,7,8,9,10]), 43)
- test.assert_equals(max_sequence([0,0,0,0,0,0,0,0,0,99,-1, 23, 43]), 164)
- test.assert_equals(max_sequence([0] * 10), 0)
- test.assert_equals(max_sequence([-1] * 10), 0)
- test.assert_equals(max_sequence([1] * 10), 10)
#include <string> #include <numeric> #include <algorithm> #include <string_view> class StringComparer { public: static inline auto verifySum(std::string_view w1, std::string_view w2) -> bool { return sumOfCharacters(w1) == sumOfCharacters(w2); } static inline auto sumOfCharacters(std::string_view word) -> int { return std::accumulate(std::begin(word), std::end(word), 0, [](int sum, char ch) { return sum + ch; }); } };
- #include <string>
- #include <numeric>
- #include <algorithm>
- #include <string_view>
- class StringComparer {
- public:
- static inline auto verifySum(std::string_view w1, std::string_view w2) -> bool {
- return sumOfCharacters(w1) == sumOfCharacters(w2);
- }
- static inline auto sumOfCharacters(std::string_view word) -> int {
return std::accumulate(std::begin(word), std::end(word), 0, [](int sum, const char ch) {return sum + static_cast<int>(ch);- return std::accumulate(std::begin(word), std::end(word), 0, [](int sum, char ch) {
- return sum + ch;
- });
- }
- };
def you_are_cool(n="Taki"): if not isinstance(n, str): return "Wait, so your name ISN'T a string of text?! That's wild!" n = n.strip() if not n: return "There is no name, so I'm not complimenting you. LOL" if len(n) > 100: return "Man, you have an insanely long name! Do people call you by your full name or just a nickname?" if n.isdigit(): return "Are you sure? That looks like a number. Unless you're secretly a robot with a numerical name!" return f"Hello {n}, you are very cool!" # edge case go BRRR
- def you_are_cool(n="Taki"):
- if not isinstance(n, str):
- return "Wait, so your name ISN'T a string of text?! That's wild!"
- n = n.strip()
- if not n:
- return "There is no name, so I'm not complimenting you. LOL"
elif len(n) > 100:- if len(n) > 100:
- return "Man, you have an insanely long name! Do people call you by your full name or just a nickname?"
elif n.isdigit():- if n.isdigit():
- return "Are you sure? That looks like a number. Unless you're secretly a robot with a numerical name!"
else:return f"Hello {n}, you are very cool!"- return f"Hello {n}, you are very cool!"
- # edge case go BRRR
Implement as trait
pub trait Matrix { fn determinant(&self) -> i32; fn rows(&self) -> usize; fn cols(&self) -> usize; fn cofactor_matrix(&self, row: usize, col: usize) -> Self; } impl Matrix for Vec<Vec<i32>> { fn determinant(&self) -> i32 { if self.rows() == 2 && self.cols() == 2 { self[0][0] * self[1][1] - self[0][1] * self[1][0] } else { (0..self.cols()).map(|col| (-1i32).pow(col as u32) * self[0][col] * self.cofactor_matrix(0, col).determinant() ).sum() } } fn rows(&self) -> usize { self.len() } fn cols(&self) -> usize { self[0].len() } fn cofactor_matrix(&self, row: usize, col: usize) -> Self { let mut cofactor = vec![vec![0;self.cols()-1];self.rows()-1]; for (target_row, source_row) in (0..self.rows()).filter(|&n| n != row).enumerate() { for (target_col, source_col) in (0..self.cols()).filter(|&n| n != col).enumerate() { cofactor[target_row][target_col] = self[source_row][source_col]; } } cofactor } }
pub struct Matrix(Vec<Vec<i32>>);- pub trait Matrix {
- fn determinant(&self) -> i32;
- fn rows(&self) -> usize;
- fn cols(&self) -> usize;
- fn cofactor_matrix(&self, row: usize, col: usize) -> Self;
- }
impl Matrix {pub fn new(elements: Vec<Vec<i32>>) -> Self {Self(elements)}pub fn determinant(&self) -> i32 {- impl Matrix for Vec<Vec<i32>> {
- fn determinant(&self) -> i32 {
- if self.rows() == 2 && self.cols() == 2 {
self.0[0][0] * self.0[1][1] - self.0[0][1] * self.0[1][0]- self[0][0] * self[1][1] - self[0][1] * self[1][0]
- } else {
(0..self.cols()).map(|col| (-1i32).pow(col as u32) * self.0[0][col] * self.cofactor_matrix(0, col).determinant()).sum()- (0..self.cols()).map(|col|
- (-1i32).pow(col as u32) * self[0][col] * self.cofactor_matrix(0, col).determinant()
- ).sum()
- }
- }
- fn rows(&self) -> usize {
self.0.len()- self.len()
- }
- fn cols(&self) -> usize {
self.0[0].len()- self[0].len()
- }
- fn cofactor_matrix(&self, row: usize, col: usize) -> Self {
let mut cofactor_inner = vec![vec![0;self.cols()-1];self.rows()-1];- let mut cofactor = vec![vec![0;self.cols()-1];self.rows()-1];
- for (target_row, source_row) in (0..self.rows()).filter(|&n| n != row).enumerate() {
- for (target_col, source_col) in (0..self.cols()).filter(|&n| n != col).enumerate() {
cofactor_inner[target_row][target_col] = self.0[source_row][source_col];- cofactor[target_row][target_col] = self[source_row][source_col];
- }
- }
Matrix::new(cofactor_inner)- cofactor
- }
- }
#[cfg(test)] mod tests { use super::Matrix; #[test] fn test_identity() { let matrix = vec![ vec![1, 0], vec![0, 1], ]; assert_eq!(matrix.determinant(), 1); let matrix = vec![ vec![1, 0, 0], vec![0, 1, 0], vec![0, 0, 1], ]; assert_eq!(matrix.determinant(), 1); let matrix = vec![ vec![1, 0, 0, 0], vec![0, 1, 0, 0], vec![0, 0, 1, 0], vec![0, 0, 0, 1], ]; assert_eq!(matrix.determinant(), 1); let matrix = vec![ vec![1, 0, 0, 0, 0], vec![0, 1, 0, 0, 0], vec![0, 0, 1, 0, 0], vec![0, 0, 0, 1, 0], vec![0, 0, 0, 0, 1], ]; assert_eq!(matrix.determinant(), 1); } #[test] fn test_2_by_2() { let matrix = vec![ vec![1, 1], vec![1, 1], ]; assert_eq!(matrix.determinant(), 0); let matrix = vec![ vec![0, 1], vec![1, 0], ]; assert_eq!(matrix.determinant(), -1); let matrix = vec![ vec![5, -2], vec![1, 4], ]; assert_eq!(matrix.determinant(), 22); } #[test] fn test_3_by_3() { let matrix = vec![ vec![5, 2, 0], vec![0, 1, 0], vec![2, 0, 1], ]; assert_eq!(matrix.determinant(), 5); let matrix = vec![ vec![5, 2, 0], vec![4, 1, 0], vec![2, 0, 1], ]; assert_eq!(matrix.determinant(), -3); } #[test] fn test_4_by_4() { let matrix = vec![ vec![5, 2, 0, 4], vec![0, 1, 0, -15], vec![2, 0, 1, 10], vec![2, 0, 1, 2], ]; assert_eq!(matrix.determinant(), -40); } }
- #[cfg(test)]
- mod tests {
use super::*;- use super::Matrix;
- #[test]
- fn test_identity() {
let matrix = Matrix::new(vec![- let matrix = vec![
- vec![1, 0],
- vec![0, 1],
]);- ];
- assert_eq!(matrix.determinant(), 1);
let matrix = Matrix::new(vec![- let matrix = vec![
- vec![1, 0, 0],
- vec![0, 1, 0],
- vec![0, 0, 1],
]);- ];
- assert_eq!(matrix.determinant(), 1);
let matrix = Matrix::new(vec![- let matrix = vec![
- vec![1, 0, 0, 0],
- vec![0, 1, 0, 0],
- vec![0, 0, 1, 0],
- vec![0, 0, 0, 1],
]);- ];
- assert_eq!(matrix.determinant(), 1);
let matrix = Matrix::new(vec![- let matrix = vec![
- vec![1, 0, 0, 0, 0],
- vec![0, 1, 0, 0, 0],
- vec![0, 0, 1, 0, 0],
- vec![0, 0, 0, 1, 0],
- vec![0, 0, 0, 0, 1],
]);- ];
- assert_eq!(matrix.determinant(), 1);
- }
- #[test]
- fn test_2_by_2() {
let matrix = Matrix::new(vec![- let matrix = vec![
- vec![1, 1],
- vec![1, 1],
]);- ];
- assert_eq!(matrix.determinant(), 0);
let matrix = Matrix::new(vec![- let matrix = vec![
- vec![0, 1],
- vec![1, 0],
]);- ];
- assert_eq!(matrix.determinant(), -1);
let matrix = Matrix::new(vec![- let matrix = vec![
- vec![5, -2],
- vec![1, 4],
]);- ];
- assert_eq!(matrix.determinant(), 22);
- }
- #[test]
- fn test_3_by_3() {
let matrix = Matrix::new(vec![- let matrix = vec![
- vec![5, 2, 0],
- vec![0, 1, 0],
- vec![2, 0, 1],
]);- ];
- assert_eq!(matrix.determinant(), 5);
let matrix = Matrix::new(vec![- let matrix = vec![
- vec![5, 2, 0],
- vec![4, 1, 0],
- vec![2, 0, 1],
]);- ];
- assert_eq!(matrix.determinant(), -3);
- }
- #[test]
- fn test_4_by_4() {
let matrix = Matrix::new(vec![- let matrix = vec![
- vec![5, 2, 0, 4],
- vec![0, 1, 0, -15],
- vec![2, 0, 1, 10],
- vec![2, 0, 1, 2],
]);- ];
- assert_eq!(matrix.determinant(), -40);
- }
- }