Skip to content

Commit

Permalink
Check code style against clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
lelandjansen committed Nov 9, 2017
1 parent 79a1b8d commit 22ec1fd
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 66 deletions.
9 changes: 9 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
version: 2
jobs:
check-code-style:
docker:
- image: lelandjansen/speed-of-sound-toolchain:0.0.2
steps:
- checkout
- run:
name: Check code style
command: ./check-code-style
build-release:
docker:
- image: lelandjansen/speed-of-sound-toolchain:0.0.2
Expand Down Expand Up @@ -43,6 +51,7 @@ workflows:
version: 2
build_and_test:
jobs:
- check-code-style
- build-release
- build-debug-and-test

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build*/
*.swp
*.swo
.DS_Store

13 changes: 13 additions & 0 deletions check-code-style
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/python3

import subprocess
output = subprocess.check_output(['git', 'clang-format-5.0',
'--binary', 'clang-format-5.0', '--commit', 'HEAD~1', '--diff'])

if output.strip().lower() not in [b'no modified files to format',
b'clang-format did not modify any files']:
print('Code style does not match clang-format')
print(output.strip().decode('utf-8'))
exit(1)
exit(0)

Binary file removed src/.speed-of-sound.cc.swo
Binary file not shown.
25 changes: 16 additions & 9 deletions src/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

namespace speedofsound {

Environment::Environment() :
temperature_(theory::kStdTemperature), humidity_(theory::kStdHumidity), pressure_(theory::kStdPressure), co2_mole_fraction_(theory::kStdCO2MoleFraction) {
}
Environment::Environment()
: temperature_(theory::kStdTemperature),
humidity_(theory::kStdHumidity),
pressure_(theory::kStdPressure),
co2_mole_fraction_(theory::kStdCO2MoleFraction) {}

auto Environment::ValidateTemperature() const -> bool {
return theory::kMinTemperature <= temperature_ && temperature_ <= theory::kMaxTemperature;
return theory::kMinTemperature <= temperature_ &&
temperature_ <= theory::kMaxTemperature;
}

auto Environment::ValidateHumidity() const -> bool {
Expand All @@ -21,15 +24,19 @@ auto Environment::ValidatePressure() const -> bool {
}

auto Environment::ValidateCO2MoleFraction() const -> bool {
return theory::kMinCO2MoleFraction <= co2_mole_fraction_ && co2_mole_fraction_ <= theory::kMaxCO2MoleFraction;
return theory::kMinCO2MoleFraction <= co2_mole_fraction_ &&
co2_mole_fraction_ <= theory::kMaxCO2MoleFraction;
}

auto Environment::ValidateEnvironment() const -> bool {
return ValidateTemperature() && ValidateHumidity() && ValidatePressure() && ValidateCO2MoleFraction();
return ValidateTemperature() && ValidateHumidity() && ValidatePressure() &&
ValidateCO2MoleFraction();
}

EnvironmentRate::EnvironmentRate() : temperature_rate_(0.0), humidity_rate_(0.0), pressure_rate_(0.0), co2_mole_fraction_rate_(0.0) {
}
EnvironmentRate::EnvironmentRate()
: temperature_rate_(0.0),
humidity_rate_(0.0),
pressure_rate_(0.0),
co2_mole_fraction_rate_(0.0) {}

} // namespace speedofsound

1 change: 0 additions & 1 deletion src/environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@ class EnvironmentRate {
} // namespace speedofsound

#endif // ENVIRONMENT_H_

45 changes: 32 additions & 13 deletions src/speed-of-sound-theory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ auto T(const double t) -> double { return t + 273.15; }

auto dT_dt() -> double { return 1.0; }

auto F(const double p, const double t) -> double { return k16 + k17 * p + k18 * t * t; }
auto F(const double p, const double t) -> double {
return k16 + k17 * p + k18 * t * t;
}

auto dF_dp() -> double { return k17; }

Expand All @@ -59,21 +61,32 @@ auto dPsv_dt(const double T) -> double {
return dPsv_dt;
}

auto Xw(const double h, const double F, const double Psv, const double p) -> double { return h * F * Psv / p; }
auto Xw(const double h, const double F, const double Psv, const double p)
-> double {
return h * F * Psv / p;
}

auto dXw_dh(const double F, const double Psv, const double p) -> double { return F * Psv / p; }
auto dXw_dh(const double F, const double Psv, const double p) -> double {
return F * Psv / p;
}

auto dXw_dF(const double h, const double Psv, const double p) -> double { return h * Psv / p; }
auto dXw_dF(const double h, const double Psv, const double p) -> double {
return h * Psv / p;
}

auto dXw_dPsv(const double h, const double F, const double p) -> double { return h * F / p; }
auto dXw_dPsv(const double h, const double F, const double p) -> double {
return h * F / p;
}

auto dXw_dp(const double h, const double F, const double Psv, const double p) -> double {
auto dXw_dp(const double h, const double F, const double Psv, const double p)
-> double {
auto dXw_dp = -h * F * Psv / (p * p);
dXw_dp += h * dF_dp() * Psv / p;
return dXw_dp;
}

auto C(const double t, const double p, const double Xw, const double xc) -> double {
auto C(const double t, const double p, const double Xw, const double xc)
-> double {
auto C = k00 + k01 * t + k02 * t * t;
C += (k03 + k04 * t + k05 * t * t) * Xw;
C += (k06 + k07 * t + k08 * t * t) * p;
Expand All @@ -85,7 +98,9 @@ auto C(const double t, const double p, const double Xw, const double xc) -> doub
return C;
}

auto dC_dt(const double t, const double p, const double Xw, const double xc, const double dXw_dF, const double dF_dt, const double dXw_dPsv, const double dPsv_dt) -> double {
auto dC_dt(const double t, const double p, const double Xw, const double xc,
const double dXw_dF, const double dF_dt, const double dXw_dPsv,
const double dPsv_dt) -> double {
auto dC_dt = k01 + 2.0 * k02 * t;
dC_dt += (k04 + 2.0 * k05 * t) * Xw;
dC_dt += (k03 + k04 * t + k05 * t * t) * dXw_dPsv * dPsv_dt;
Expand All @@ -99,14 +114,16 @@ auto dC_dt(const double t, const double p, const double Xw, const double xc, con
return dC_dt;
}

auto dC_dXw(const double t, const double p, const double Xw, const double xc) -> double {
auto dC_dXw(const double t, const double p, const double Xw, const double xc)
-> double {
auto dC_dXw = k03 + k04 * t + k05 * t * t;
dC_dXw += 2.0 * k12 * Xw;
dC_dXw += k15 * xc * p;
return dC_dXw;
}

auto dC_dp(const double t, const double p, const double Xw, const double xc, const double dXw_dp) -> double {
auto dC_dp(const double t, const double p, const double Xw, const double xc,
const double dXw_dp) -> double {
auto dC_dp = (k03 + k04 * t + k05 * t * t) * dXw_dp;
dC_dp += k06 + k07 * t + k08 * t * t;
dC_dp += 2.0 * k12 * Xw * dXw_dp;
Expand All @@ -116,16 +133,18 @@ auto dC_dp(const double t, const double p, const double Xw, const double xc, con
return dC_dp;
}

auto dC_dxc(const double t, const double p, const double Xw, const double xc) -> double {
auto dC_dxc(const double t, const double p, const double Xw, const double xc)
-> double {
auto dC_dxc = k09 + k10 * t + k11 * t * t;
dC_dxc += 2.0 * k14 * xc;
dC_dxc += k15 * p * Xw;
return dC_dxc;
}

auto dC_dh(const double dC_dXw, const double dXw_dh) -> double { return dC_dXw * dXw_dh; }
auto dC_dh(const double dC_dXw, const double dXw_dh) -> double {
return dC_dXw * dXw_dh;
}

} // namespace theory

} // namespace speedofsound

25 changes: 16 additions & 9 deletions src/speed-of-sound-theory.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,29 @@ auto dF_dt(const double t) -> double;
auto Psv(const double T) -> double;
auto dPsv_dt(const double T) -> double;

auto Xw(const double h, const double F, const double Psv, const double p) -> double;
auto Xw(const double h, const double F, const double Psv, const double p)
-> double;
auto dXw_dh(const double F, const double Psv, const double p) -> double;
auto dXw_dF(const double h, const double Psv, const double p) -> double;
auto dXw_dPsv(const double h, const double F, const double p) -> double;
auto dXw_dp(const double h, const double F, const double Psv, const double p) -> double;

auto C(const double t, const double p, const double Xw, const double xc) -> double;
auto dC_dt(const double t, const double p, const double Xw, const double xc, const double dXw_dF, const double dF_dt, const double dXw_dPsv, const double dPsv_dt) -> double;
auto dC_dXw(const double t, const double p, const double Xw, const double xc) -> double;
auto dC_dxc(const double t, const double p, const double Xw, const double xc) -> double;
auto dC_dp(const double t, const double p, const double Xw, const double xc, const double dXw_dp) -> double;
auto dXw_dp(const double h, const double F, const double Psv, const double p)
-> double;

auto C(const double t, const double p, const double Xw, const double xc)
-> double;
auto dC_dt(const double t, const double p, const double Xw, const double xc,
const double dXw_dF, const double dF_dt, const double dXw_dPsv,
const double dPsv_dt) -> double;
auto dC_dXw(const double t, const double p, const double Xw, const double xc)
-> double;
auto dC_dxc(const double t, const double p, const double Xw, const double xc)
-> double;
auto dC_dp(const double t, const double p, const double Xw, const double xc,
const double dXw_dp) -> double;
auto dC_dh(const double dC_dXw, const double dXw_dh) -> double;

} // namespace theory

} // namespace speedofsound

#endif // SPEED_OF_SOUND_THEORY_H_

16 changes: 9 additions & 7 deletions src/speed-of-sound.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ namespace speedofsound {

SpeedOfSound::SpeedOfSound() { SpeedOfSound::Compute(init_environment_); }

SpeedOfSound::SpeedOfSound(const Environment& ambient_conitions) : init_environment_(ambient_conitions), init_speed_of_sound_(Compute(ambient_conitions)) {
}
SpeedOfSound::SpeedOfSound(const Environment& ambient_conitions) : init_environment_(ambient_conitions), init_speed_of_sound_(Compute(ambient_conitions)) {}

auto SpeedOfSound::GetInitEnvironment() const -> Environment {
return init_environment_;
Expand All @@ -31,7 +30,8 @@ auto SpeedOfSound::Compute(const Environment& ambient_conitions) -> double {
const auto dXw_dPsv = theory::dXw_dPsv(h, F, p);
const auto dXw_dp = theory::dXw_dp(h, F, Psv, p);
const auto dXw_dh = theory::dXw_dh(F, Psv, p);
const auto dC_dt = theory::dC_dt(t, p, Xw, xc, dXw_dF, dF_dt, dXw_dPsv, dPsv_dt);
const auto dC_dt =
theory::dC_dt(t, p, Xw, xc, dXw_dF, dF_dt, dXw_dPsv, dPsv_dt);
const auto dC_dxc = theory::dC_dxc(t, p, Xw, xc);
const auto dC_dp = theory::dC_dp(t, p, Xw, xc, dXw_dp);
const auto dC_dXw = theory::dC_dXw(t, p, Xw, xc);
Expand All @@ -48,7 +48,8 @@ auto SpeedOfSound::Compute(const Environment& ambient_conitions) -> double {
return init_speed_of_sound_;
}

auto SpeedOfSound::QuickCompute(const Environment& ambient_conitions) const -> double {
auto SpeedOfSound::QuickCompute(const Environment& ambient_conitions) const
-> double {
const auto t = ambient_conitions.temperature_;
const auto h = ambient_conitions.humidity_;
const auto p = ambient_conitions.pressure_;
Expand All @@ -60,7 +61,8 @@ auto SpeedOfSound::QuickCompute(const Environment& ambient_conitions) const -> d
return theory::C(t, p, Xw, xc);
}

auto SpeedOfSound::Approximate(const Environment& ambient_conitions) const -> double {
auto SpeedOfSound::Approximate(const Environment& ambient_conitions) const
-> double {
auto approx_speed_of_sound = init_speed_of_sound_;
auto speed_of_sound_change = 0.0;
if (ambient_conitions.temperature_ != init_environment_.temperature_) {
Expand All @@ -81,7 +83,8 @@ auto SpeedOfSound::Approximate(const Environment& ambient_conitions) const -> do
speed_of_sound_change *= init_environment_rate_.pressure_rate_;
approx_speed_of_sound += speed_of_sound_change;
}
if (ambient_conitions.co2_mole_fraction_ != init_environment_.co2_mole_fraction_) {
if (ambient_conitions.co2_mole_fraction_ !=
init_environment_.co2_mole_fraction_) {
speed_of_sound_change = ambient_conitions.co2_mole_fraction_;
speed_of_sound_change -= init_environment_.co2_mole_fraction_;
speed_of_sound_change *= init_environment_rate_.co2_mole_fraction_rate_;
Expand All @@ -91,4 +94,3 @@ auto SpeedOfSound::Approximate(const Environment& ambient_conitions) const -> do
}

} // namespace speedofsound

5 changes: 2 additions & 3 deletions src/speed-of-sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class SpeedOfSound {
public:
SpeedOfSound();
SpeedOfSound(const Environment& ambient_conitions);
auto GetInitEnvironment() const-> Environment ;
auto GetInitEnvironmentRate() const -> EnvironmentRate ;
auto GetInitEnvironment() const -> Environment;
auto GetInitEnvironmentRate() const -> EnvironmentRate;
auto Compute(const Environment& ambient_conitions) -> double;
auto QuickCompute(const Environment& ambient_conitions) const -> double;
auto Approximate(const Environment& ambient_conitions) const -> double;
Expand All @@ -26,4 +26,3 @@ class SpeedOfSound {
} // namespace speedofsound

#endif // SPEED_OF_SOUND_H_

1 change: 0 additions & 1 deletion test/speed-of-sound-theory_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ class SpeedOfSoundTheoryTest : public ::testing::Test {
};

#endif

0 comments on commit 22ec1fd

Please sign in to comment.