Skip to content

Commit 5835e37

Browse files
refactor: clean up mul_add_assign_tests module
1 parent af6e580 commit 5835e37

File tree

1 file changed

+16
-55
lines changed

1 file changed

+16
-55
lines changed

crates/proof-of-sql/src/base/slice_ops/mul_add_assign_test.rs

Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,24 @@ use crate::base::scalar::test_scalar::TestScalar;
33

44
#[test]
55
fn test_mul_add_assign() {
6-
let mut a = vec![
7-
TestScalar::from(1i32),
8-
TestScalar::from(2i32),
9-
TestScalar::from(3i32),
10-
TestScalar::from(4i32),
11-
];
6+
let mut a = [1, 2, 3, 4].map(TestScalar::from).to_vec();
127
let b = vec![2, 3, 4, 5];
138
mul_add_assign(&mut a, TestScalar::from(10i32), &b);
14-
let c = vec![
15-
TestScalar::from(1 + 10 * 2),
16-
TestScalar::from(2 + 10 * 3),
17-
TestScalar::from(3 + 10 * 4),
18-
TestScalar::from(4 + 10 * 5),
19-
];
9+
let c = [1 + 10 * 2, 2 + 10 * 3, 3 + 10 * 4, 4 + 10 * 5]
10+
.map(TestScalar::from)
11+
.to_vec();
2012
assert_eq!(a, c);
2113
}
2214

2315
/// test [`mul_add_assign`] with uneven vectors
2416
#[test]
2517
fn test_mul_add_assign_uneven() {
26-
let mut a = vec![
27-
TestScalar::from(1u32),
28-
TestScalar::from(2u32),
29-
TestScalar::from(3u32),
30-
TestScalar::from(4u32),
31-
TestScalar::from(5u32),
32-
];
33-
let b = vec![
34-
TestScalar::from(2u32),
35-
TestScalar::from(3u32),
36-
TestScalar::from(4u32),
37-
TestScalar::from(5u32),
38-
];
18+
let mut a = [1, 2, 3, 4, 5].map(TestScalar::from).to_vec();
19+
let b = [2, 3, 4, 5].map(TestScalar::from).to_vec();
3920
mul_add_assign(&mut a, TestScalar::from(10u32), &b);
40-
let c = vec![
41-
TestScalar::from(1 + 10 * 2),
42-
TestScalar::from(2 + 10 * 3),
43-
TestScalar::from(3 + 10 * 4),
44-
TestScalar::from(4 + 10 * 5),
45-
TestScalar::from(5u32),
46-
];
21+
let c = [1 + 10 * 2, 2 + 10 * 3, 3 + 10 * 4, 4 + 10 * 5, 5]
22+
.map(TestScalar::from)
23+
.to_vec();
4724
assert_eq!(a, c);
4825
}
4926

@@ -53,43 +30,27 @@ fn test_mul_add_assign_uneven() {
5330
expected = "The length of result must be greater than or equal to the length of the vector of values to be multiplied and added"
5431
)]
5532
fn test_mul_add_assign_uneven_panic() {
56-
let mut a = vec![
57-
TestScalar::from(1u32),
58-
TestScalar::from(2u32),
59-
TestScalar::from(3u32),
60-
TestScalar::from(4u32),
61-
];
33+
let mut a = [1u32, 2u32, 3u32, 4u32].map(TestScalar::from).to_vec();
6234
let b = vec![2, 3, 4, 5, 6];
6335
mul_add_assign(&mut a, TestScalar::from(10u32), &b);
6436
}
6537

6638
/// test [`mul_add_assign`] with `TestScalar`
6739
#[test]
6840
fn test_mul_add_assign_testscalar() {
69-
let mut a = vec![TestScalar::from(1u64), TestScalar::from(2u64)];
70-
let b = vec![TestScalar::from(2u64), TestScalar::from(3u64)];
41+
let mut a = [1, 2].map(TestScalar::from).to_vec();
42+
let b = [2, 3].map(TestScalar::from).to_vec();
7143
mul_add_assign(&mut a, TestScalar::from(10u64), &b);
72-
let c = vec![
73-
TestScalar::from(1u64) + TestScalar::from(10u64) * TestScalar::from(2u64),
74-
TestScalar::from(2u64) + TestScalar::from(10u64) * TestScalar::from(3u64),
75-
];
44+
let c = [1 + 10 * 2, 2 + 10 * 3].map(TestScalar::from).to_vec();
7645
assert_eq!(a, c);
7746
}
7847

7948
/// test [`mul_add_assign`] with uneven `TestScalar`
8049
#[test]
8150
fn test_mul_add_assign_testscalar_uneven() {
82-
let mut a = vec![
83-
TestScalar::from(1u64),
84-
TestScalar::from(2u64),
85-
TestScalar::from(3u64),
86-
];
87-
let b = vec![TestScalar::from(2u64), TestScalar::from(3u64)];
51+
let mut a = [1, 2, 3].map(TestScalar::from).to_vec();
52+
let b = [2, 3].map(TestScalar::from).to_vec();
8853
mul_add_assign(&mut a, TestScalar::from(10u64), &b);
89-
let c = vec![
90-
TestScalar::from(1u64) + TestScalar::from(10u64) * TestScalar::from(2u64),
91-
TestScalar::from(2u64) + TestScalar::from(10u64) * TestScalar::from(3u64),
92-
TestScalar::from(3u64),
93-
];
54+
let c = [1 + 10 * 2, 2 + 10 * 3, 3].map(TestScalar::from).to_vec();
9455
assert_eq!(a, c);
9556
}

0 commit comments

Comments
 (0)