-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add electronics/coulombs law module #840
base: master
Are you sure you want to change the base?
Conversation
add documentation in readme.md
use macro for test
initial coulombs_law module with tests
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #840 +/- ##
=======================================
Coverage 95.44% 95.45%
=======================================
Files 316 318 +2
Lines 22839 22887 +48
=======================================
+ Hits 21798 21846 +48
Misses 1041 1041 ☔ View full report in Codecov by Sentry. |
initial search_in_a_sorted_matrix with tests
Merge branch 'master' of https://github.com/alirezasariri78/Rust
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file relevant in this PR? If not, please remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this module is located in python repository : https://github.com/TheAlgorithms/Python/blob/master/matrix/searching_in_sorted_matrix.py
pub fn coulombs_law( | ||
force: f64, | ||
charge1: f64, | ||
charge2: f64, | ||
distance: f64, | ||
) -> Result<String, CoulombsLawError> { | ||
let charge_product = (charge1 * charge2).abs(); | ||
|
||
if invalid_arguments(force, charge1, charge2, distance) { | ||
return Err(CoulombsLawError::ExtraZeroArg(String::from( | ||
"One and only one argument must be 0", | ||
))); | ||
} | ||
|
||
if distance < 0.0 { | ||
return Err(CoulombsLawError::NegativeDistance(String::from( | ||
"Distance cannot be negative", | ||
))); | ||
} | ||
|
||
if force == 0.0 { | ||
return Ok(format!( | ||
"force: {}", | ||
calculate_force(charge_product, distance) | ||
)); | ||
} else if charge1 == 0.0 { | ||
return Ok(format!( | ||
"charge1: {}", | ||
calculate_charge(charge2, force, distance) | ||
)); | ||
} else if charge2 == 0.0 { | ||
return Ok(format!( | ||
"charge2: {}", | ||
calculate_charge(charge1, force, distance) | ||
)); | ||
} | ||
Ok(format!( | ||
"distance: {}", | ||
calculate_distance(charge_product, force) | ||
)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this function really needed? If you insist on having it, please consider using Optional
as inputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
based on electronic modules in python repository : https://github.com/TheAlgorithms/Python/blob/master/electronics/coulombs_law.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using optional would not cause boiler plate ?
in this situation i should double check value of inputs (none or some and sign of inputs)
Pull Request Template
Description
Please include a summary of the change and which issue (if any) is fixed.
A brief description of the algorithm and your implementation method can be helpful too. If the implemented method/algorithm is not so
well-known, it would be helpful to add a link to an article explaining it with more details.
Type of change
Please delete options that are not relevant.
Checklist:
cargo clippy --all -- -D warnings
just before my last commit and fixed any issue that was found.cargo fmt
just before my last commit.cargo test
just before my last commit and all tests passed.mod.rs
file within its own folder, and in any parent folder(s).DIRECTORY.md
with the correct link.COUNTRIBUTING.md
and my code follows its guidelines.Please make sure that if there is a test that takes too long to run ( > 300ms), you
#[ignore]
that ortry to optimize your code or make the test easier to run. We have this rule because we have hundreds of
tests to run; If each one of them took 300ms, we would have to wait for a long time.