Skip to content

Commit

Permalink
Add problem 2235: Add Two Integers
Browse files Browse the repository at this point in the history
  • Loading branch information
EFanZh committed Mar 22, 2024
1 parent e04f46e commit 637d68b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,7 @@ pub mod problem_2215_find_the_difference_of_two_arrays;
pub mod problem_2216_minimum_deletions_to_make_array_beautiful;
pub mod problem_2220_minimum_bit_flips_to_convert_number;
pub mod problem_2231_largest_number_after_digit_swaps_by_parity;
pub mod problem_2235_add_two_integers;

#[cfg(test)]
mod test_utilities;
18 changes: 18 additions & 0 deletions src/problem_2235_add_two_integers/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pub mod obvious;

pub trait Solution {
fn sum(num1: i32, num2: i32) -> i32;
}

#[cfg(test)]
mod tests {
use super::Solution;

pub fn run<S: Solution>() {
let test_cases = [((12, 5), 17), ((-10, 4), -6)];

for ((num1, num2), expected) in test_cases {
assert_eq!(S::sum(num1, num2), expected);
}
}
}
25 changes: 25 additions & 0 deletions src/problem_2235_add_two_integers/obvious.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pub struct Solution;

// ------------------------------------------------------ snip ------------------------------------------------------ //

impl Solution {
pub fn sum(num1: i32, num2: i32) -> i32 {
num1 + num2
}
}

// ------------------------------------------------------ snip ------------------------------------------------------ //

impl super::Solution for Solution {
fn sum(num1: i32, num2: i32) -> i32 {
Self::sum(num1, num2)
}
}

#[cfg(test)]
mod tests {
#[test]
fn test_solution() {
super::super::tests::run::<super::Solution>();
}
}

0 comments on commit 637d68b

Please sign in to comment.