WIP: feat: Change soring behaviour and add new testcase
This commit is contained in:
parent
bad946e9ac
commit
b63dc86c7e
2 changed files with 66 additions and 9 deletions
|
|
@ -138,4 +138,58 @@ mod tests {
|
|||
assert_eq!(json!(result), expected);
|
||||
//assert_eq!(BASE64_STANDARD.encode(product), "MoAAAAAAAAAAAAAAAAAAAA==");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_poly_sorting_02() {
|
||||
let json1 = json!(
|
||||
{"polys": [
|
||||
[
|
||||
"AQAAAAAAAAAAAAAAAAAAAA==", // 0x01
|
||||
"AgAAAAAAAAAAAAAAAAAAAA==", // 0x02
|
||||
"AwAAAAAAAAAAAAAAAAAAAA==" // 0x03
|
||||
],
|
||||
[
|
||||
"AQAAAAAAAAAAAAAAAAAAAA==", // 0x01
|
||||
"AgAAAAAAAAAAAAAAAAAAAA==", // 0x02
|
||||
"BAAAAAAAAAAAAAAAAAAAAA==" // 0x04
|
||||
],
|
||||
[
|
||||
"AQAAAAAAAAAAAAAAAAAAAA==", // 0x01
|
||||
"AgAAAAAAAAAAAAAAAAAAAA==" // 0x02
|
||||
],
|
||||
[
|
||||
"AQAAAAAAAAAAAAAAAAAAAA==", // 0x01
|
||||
"AwAAAAAAAAAAAAAAAAAAAA==" // 0x03
|
||||
]
|
||||
],});
|
||||
|
||||
let expected = json!([
|
||||
[
|
||||
"WereNoStrangersToLoveA==",
|
||||
"YouKnowTheRulesAAAAAAA==",
|
||||
"AndSoDoIAAAAAAAAAAAAAA=="
|
||||
],
|
||||
[
|
||||
"NeverGonnaMakeYouCryAA==",
|
||||
"NeverGonnaSayGoodbyeAA==",
|
||||
"NeverGonnaTellALieAAAA==",
|
||||
"AndHurtYouAAAAAAAAAAAA=="
|
||||
],
|
||||
[
|
||||
"NeverGonnaGiveYouUpAAA==",
|
||||
"NeverGonnaLetYouDownAA==",
|
||||
"NeverGonnaRunAroundAAA==",
|
||||
"AndDesertYouAAAAAAAAAA=="
|
||||
]
|
||||
]);
|
||||
|
||||
let sorted_array = gfpoly_sort(&json1).unwrap();
|
||||
let mut result: Vec<Vec<String>> = vec![];
|
||||
for poly in sorted_array {
|
||||
result.push(poly.to_c_array());
|
||||
}
|
||||
|
||||
assert_eq!(json!(result), expected);
|
||||
//assert_eq!(BASE64_STANDARD.encode(product), "MoAAAAAAAAAAAAAAAAAAAA==");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -324,17 +324,20 @@ impl PartialEq for Polynomial {
|
|||
}
|
||||
|
||||
impl PartialOrd for Polynomial {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
if self.polynomial.len() != other.polynomial.len() {
|
||||
return Some(self.polynomial.len().cmp(&other.polynomial.len()));
|
||||
} else {
|
||||
for (field_a, field_b) in self.as_ref().iter().rev().zip(other.as_ref().iter().rev()) {
|
||||
match field_a.cmp(field_b) {
|
||||
std::cmp::Ordering::Equal => continue,
|
||||
other => return Some(other.reverse()),
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
match self.polynomial.len().cmp(&other.polynomial.len()) {
|
||||
Ordering::Equal => {
|
||||
for (field_a, field_b) in
|
||||
self.as_ref().iter().rev().zip(other.as_ref().iter().rev())
|
||||
{
|
||||
match field_a.cmp(field_b) {
|
||||
std::cmp::Ordering::Equal => continue,
|
||||
other => return Some(other.reverse()),
|
||||
}
|
||||
}
|
||||
Some(Ordering::Equal)
|
||||
}
|
||||
Some(Ordering::Equal)
|
||||
other => Some(other),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue