Skip to content

Commit

Permalink
palindrome-products: return owned hashset
Browse files Browse the repository at this point in the history
See feedback: exercism#2006 (comment)

Co-authored-by: Remo Senekowitsch <[email protected]>
  • Loading branch information
ellnix and senekor committed Jan 30, 2025
1 parent a924024 commit 9512a58
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions exercises/practice/palindrome-products/.meta/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ impl Palindrome {
self.value
}

pub fn factors(&self) -> &HashSet<(u64, u64)> {
&self.factors
pub fn into_factors(self) -> HashSet<(u64, u64)> {
self.factors
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn {{ test.description | make_ident }}() {
let (_, pal) = output.unwrap();
{%- endif%}
assert_eq!(pal.value(), {{ test.expected.value }});
assert_eq!(pal.factors(), &HashSet::from([
assert_eq!(pal.into_factors(), HashSet::from([
{{- test.expected.factors | join(sep=", ") | replace(from="[", to="(") | replace(from="]", to=")") -}}
]));
{%- endif%}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/palindrome-products/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl Palindrome {
todo!("return the value of the palindrome")
}

pub fn factors(&self) -> &HashSet<(u64, u64)> {
pub fn into_factors(&self) -> HashSet<(u64, u64)> {
todo!("return the set of factors of the palindrome")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fn find_the_smallest_palindrome_from_single_digit_factors() {

let (pal, _) = output.unwrap();
assert_eq!(pal.value(), 1);
assert_eq!(pal.factors(), &HashSet::from([(1, 1)]));
assert_eq!(pal.into_factors(), HashSet::from([(1, 1)]));
}

#[test]
Expand All @@ -19,7 +19,7 @@ fn find_the_largest_palindrome_from_single_digit_factors() {

let (_, pal) = output.unwrap();
assert_eq!(pal.value(), 9);
assert_eq!(pal.factors(), &HashSet::from([(1, 9), (3, 3)]));
assert_eq!(pal.into_factors(), HashSet::from([(1, 9), (3, 3)]));
}

#[test]
Expand All @@ -30,7 +30,7 @@ fn find_the_smallest_palindrome_from_double_digit_factors() {

let (pal, _) = output.unwrap();
assert_eq!(pal.value(), 121);
assert_eq!(pal.factors(), &HashSet::from([(11, 11)]));
assert_eq!(pal.into_factors(), HashSet::from([(11, 11)]));
}

#[test]
Expand All @@ -41,7 +41,7 @@ fn find_the_largest_palindrome_from_double_digit_factors() {

let (_, pal) = output.unwrap();
assert_eq!(pal.value(), 9009);
assert_eq!(pal.factors(), &HashSet::from([(91, 99)]));
assert_eq!(pal.into_factors(), HashSet::from([(91, 99)]));
}

#[test]
Expand All @@ -52,7 +52,7 @@ fn find_the_smallest_palindrome_from_triple_digit_factors() {

let (pal, _) = output.unwrap();
assert_eq!(pal.value(), 10201);
assert_eq!(pal.factors(), &HashSet::from([(101, 101)]));
assert_eq!(pal.into_factors(), HashSet::from([(101, 101)]));
}

#[test]
Expand All @@ -63,7 +63,7 @@ fn find_the_largest_palindrome_from_triple_digit_factors() {

let (_, pal) = output.unwrap();
assert_eq!(pal.value(), 906609);
assert_eq!(pal.factors(), &HashSet::from([(913, 993)]));
assert_eq!(pal.into_factors(), HashSet::from([(913, 993)]));
}

#[test]
Expand All @@ -74,7 +74,7 @@ fn find_the_smallest_palindrome_from_four_digit_factors() {

let (pal, _) = output.unwrap();
assert_eq!(pal.value(), 1002001);
assert_eq!(pal.factors(), &HashSet::from([(1001, 1001)]));
assert_eq!(pal.into_factors(), HashSet::from([(1001, 1001)]));
}

#[test]
Expand All @@ -85,7 +85,7 @@ fn find_the_largest_palindrome_from_four_digit_factors() {

let (_, pal) = output.unwrap();
assert_eq!(pal.value(), 99000099);
assert_eq!(pal.factors(), &HashSet::from([(9901, 9999)]));
assert_eq!(pal.into_factors(), HashSet::from([(9901, 9999)]));
}

#[test]
Expand Down Expand Up @@ -124,5 +124,5 @@ fn smallest_product_does_not_use_the_smallest_factor() {

let (pal, _) = output.unwrap();
assert_eq!(pal.value(), 10988901);
assert_eq!(pal.factors(), &HashSet::from([(3297, 3333)]));
assert_eq!(pal.into_factors(), HashSet::from([(3297, 3333)]));
}

0 comments on commit 9512a58

Please sign in to comment.