Skip to content
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

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

alirezasariri78
Copy link
Contributor

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.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I ran bellow commands using the latest version of rust nightly.
  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked 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 or
try 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.

@codecov-commenter
Copy link

codecov-commenter commented Nov 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.45%. Comparing base (abff887) to head (804daf4).
Report is 2 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +18 to +58
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)
))
}
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Contributor Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants