Fix tests

Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
Ivan Bushchik 2023-03-12 20:10:43 +03:00
parent e43529b29f
commit 33ea6498cf
No known key found for this signature in database
GPG key ID: 9F6DDABE11A2674D
3 changed files with 15 additions and 13 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "matrix" name = "matrix"
version = "0.1.1" version = "0.1.2"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"

View file

@ -1,6 +1,7 @@
// use rand::{thread_rng, Rng};
use std::ops::{Add, AddAssign, Mul, MulAssign}; use std::ops::{Add, AddAssign, Mul, MulAssign};
use rand::{thread_rng, Rng};
pub(crate) type Matrix<T> = Vec<Vec<T>>; pub(crate) type Matrix<T> = Vec<Vec<T>>;
fn check_valid<T>(a: &Matrix<T>) -> bool { fn check_valid<T>(a: &Matrix<T>) -> bool {
@ -63,9 +64,12 @@ pub fn mul<T: Mul<Output = T> + Copy + AddAssign + MulAssign + std::fmt::Display
Some(c) Some(c)
} }
/*
#[allow(dead_code)] #[allow(dead_code)]
fn gen_matrix<T>(i: usize, j: usize) -> Option<Matrix<T>> { fn gen_matrix<T: Mul<Output = T> + Copy + AddAssign + MulAssign + std::fmt::Display + From<i32>>(
i: usize,
j: usize,
) -> Option<Matrix<T>> {
if !(i > 0 && j > 0) { if !(i > 0 && j > 0) {
return None; return None;
} }
@ -76,7 +80,7 @@ fn gen_matrix<T>(i: usize, j: usize) -> Option<Matrix<T>> {
for a in 0..i { for a in 0..i {
m.push(vec![]); m.push(vec![]);
for _ in 0..j { for _ in 0..j {
m[a].push(rng.gen_range(0..100) as T); m[a].push(T::from(rng.gen_range(0..100)));
} }
} }
Some(m) Some(m)
@ -84,8 +88,10 @@ fn gen_matrix<T>(i: usize, j: usize) -> Option<Matrix<T>> {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*;
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
use super::*;
#[test] #[test]
fn basic_sum() { fn basic_sum() {
let a = vec![vec![1., 2.], vec![3., 4.]]; let a = vec![vec![1., 2.], vec![3., 4.]];
@ -145,10 +151,6 @@ mod test {
let a: Matrix<f64> = gen_matrix(s1, s2).unwrap(); let a: Matrix<f64> = gen_matrix(s1, s2).unwrap();
let b: Matrix<f64> = gen_matrix(s2, s3).unwrap(); let b: Matrix<f64> = gen_matrix(s2, s3).unwrap();
let c: Matrix<f64> = gen_matrix(s3, s4).unwrap(); let c: Matrix<f64> = gen_matrix(s3, s4).unwrap();
assert_eq!( assert_eq!(mul(&mul(&a, &b).unwrap(), &c).unwrap(), mul(&a, &mul(&b, &c).unwrap()).unwrap())
mul(&mul(&a, &b).unwrap(), &c).unwrap(),
mul(&a, &mul(&b, &c).unwrap()).unwrap()
)
} }
} }
*/

View file

@ -1,6 +1,6 @@
[package] [package]
name = "matrix_graphics" name = "matrix_graphics"
version = "0.1.1" version = "0.1.2"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"
@ -11,7 +11,7 @@ default = ["optimize"]
[dependencies] [dependencies]
env_logger = "0.10" env_logger = "0.10"
log = "0.4" log = "0.4"
matrix = { version = "0.1.0", path = "../matrix" } matrix = { version = "0.1.2", path = "../matrix" }
pixels = "0.11.0" pixels = "0.11.0"
winit = "0.28.1" winit = "0.28.1"
winit_input_helper = "0.14.0" winit_input_helper = "0.14.0"