Skip to content

Commit

Permalink
Convert approx_eq! calls to assert_approx_eq!
Browse files Browse the repository at this point in the history
Resolves issue #2140

No other changes were needed, all tests still passed after this
change.
  • Loading branch information
cbondurant committed Jan 15, 2023
1 parent d062962 commit 530dfc5
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ You can find its changes [documented below](#070---2021-01-01).
- Updated fluent-bundle to 0.15.1 and fluent syntax to 0.11.0 ([#1772] by [@r-ml])
- Updated usvg to 0.14.1 ([#1802] by [@r-ml])
- x11: Add logging to `Application::get_locale` ([#1876] by [@Maan2003])
- Converted all calls of `approx_eq!` in tests to `assert_approx_eq!` ([#2331] by [@cbondurant])

### Outside News

Expand Down Expand Up @@ -576,6 +577,7 @@ Last release without a changelog :(
[@ThomasMcandrew]: https:github.com/ThomasMcandrew
[@benoitryder]: https://github.com/benoitryder
[@sprocklem]: https://github.com/sprocklem
[@cbondurant]: https://github.com/cbondurant

[#599]: https://github.com/linebender/druid/pull/599
[#611]: https://github.com/linebender/druid/pull/611
Expand Down Expand Up @@ -881,6 +883,7 @@ Last release without a changelog :(
[#2320]: https://github.com/linebender/druid/pull/2320
[#2323]: https://github.com/linebender/druid/pull/2323
[#2324]: https://github.com/linebender/druid/pull/2324
[#2331]: https://github.com/linebender/druid/pull/2331

[Unreleased]: https://github.com/linebender/druid/compare/v0.7.0...master
[0.7.0]: https://github.com/linebender/druid/compare/v0.6.0...v0.7.0
Expand Down
12 changes: 6 additions & 6 deletions druid-derive/tests/with_lens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use float_cmp::approx_eq;
use float_cmp::assert_approx_eq;

use druid::Data;
use druid::Lens;
Expand All @@ -38,14 +38,14 @@ fn derive_lens() {
let number_lens = State::lens_number; //named lens for number

text_lens.with(&state, |data| assert_eq!(data, "1.0"));
number_lens.with(&state, |data| approx_eq!(f64, *data, 1.0));
number_lens.with(&state, |data| assert_approx_eq!(f64, *data, 1.0));

text_lens.with_mut(&mut state, |data| *data = "2.0".into());
number_lens.with_mut(&mut state, |data| *data = 2.0);

assert_eq!(state.text, "2.0");
approx_eq!(f64, state.number, 2.0);
approx_eq!(f64, state.ignored, 2.0);
assert_approx_eq!(f64, state.number, 2.0);
assert_approx_eq!(f64, state.ignored, 2.0);
}

#[test]
Expand All @@ -68,13 +68,13 @@ fn mix_with_data_lens() {
let number_lens = State::lens_number; //named lens for number

text_lens.with(&state, |data| assert_eq!(data, "1.0"));
number_lens.with(&state, |data| approx_eq!(f64, *data, 1.0));
number_lens.with(&state, |data| assert_approx_eq!(f64, *data, 1.0));

text_lens.with_mut(&mut state, |data| *data = "2.0".into());
number_lens.with_mut(&mut state, |data| *data = 2.0);

assert_eq!(state.text, "2.0");
approx_eq!(f64, state.number, 2.0);
assert_approx_eq!(f64, state.number, 2.0);

//test data
let two = State {
Expand Down
12 changes: 6 additions & 6 deletions druid/src/scroll_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ impl ScrollComponent {

#[cfg(test)]
mod tests {
use float_cmp::approx_eq;
use float_cmp::assert_approx_eq;

use super::*;
use crate::kurbo::Size;
Expand Down Expand Up @@ -573,7 +573,7 @@ mod tests {
"scrollbar should be contained by viewport"
);
// scrollbar should be at start of viewport
approx_eq!(
assert_approx_eq!(
f64,
scrollbar_rect.y0,
viewport.view_rect().y0 + TEST_SCROLLBAR_PAD
Expand Down Expand Up @@ -603,7 +603,7 @@ mod tests {
"scrollbar should be contained by viewport"
);
// scrollbar should be at end of viewport
approx_eq!(
assert_approx_eq!(
f64,
scrollbar_rect.y1,
viewport.view_rect().y1 - TEST_SCROLLBAR_PAD
Expand Down Expand Up @@ -688,7 +688,7 @@ mod tests {
"scrollbar should be contained by viewport"
);
// scrollbar should use SCROLLBAR_MIN_SIZE when content is much bigger than viewport
approx_eq!(f64, scrollbar_rect.height(), TEST_SCROLLBAR_MIN_SIZE);
assert_approx_eq!(f64, scrollbar_rect.height(), TEST_SCROLLBAR_MIN_SIZE);
assert_eq!(scrollbar_rect, Rect::new(86.0, 29.0, 97.0, 46.0));
}

Expand All @@ -714,12 +714,12 @@ mod tests {
"scrollbar should be contained by viewport"
);
// scrollbar should fill viewport if too small for SCROLLBAR_MIN_SIZE
approx_eq!(
assert_approx_eq!(
f64,
scrollbar_rect.y0,
viewport.view_rect().y0 + TEST_SCROLLBAR_PAD
);
approx_eq!(
assert_approx_eq!(
f64,
scrollbar_rect.y1,
viewport.view_rect().y1 - TEST_SCROLLBAR_PAD
Expand Down
10 changes: 5 additions & 5 deletions druid/src/tests/invalidation_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

//! Tests related to propagation of invalid rects.
use float_cmp::approx_eq;
use float_cmp::assert_approx_eq;
use test_log::test;

use super::*;
Expand Down Expand Up @@ -78,10 +78,10 @@ fn invalidate_scroll() {
assert_eq!(ctx.region().rects().len(), 1);
let rect = ctx.region().rects().first().unwrap();

approx_eq!(f64, rect.x0, 30.);
approx_eq!(f64, rect.y0, 40.);
approx_eq!(f64, rect.x1, 40.);
approx_eq!(f64, rect.y1, 50.);
assert_approx_eq!(f64, rect.x0, 30.);
assert_approx_eq!(f64, rect.y0, 40.);
assert_approx_eq!(f64, rect.x1, 40.);
assert_approx_eq!(f64, rect.y1, 50.);
}
}

Expand Down
4 changes: 2 additions & 2 deletions druid/src/tests/layout_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

//! Tests related to layout.
use float_cmp::approx_eq;
use float_cmp::assert_approx_eq;
use test_log::test;

use super::*;
Expand All @@ -36,7 +36,7 @@ fn simple_layout() {
harness.send_initial_events();
harness.just_layout();
let state = harness.get_state(id_1);
approx_eq!(
assert_approx_eq!(
f64,
state.layout_rect().x0,
((DEFAULT_SIZE.width - BOX_WIDTH) / 2.) - PADDING
Expand Down
8 changes: 4 additions & 4 deletions druid/src/widget/flex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,14 +1272,14 @@ mod tests {
#[test]
#[should_panic]
fn test_invalid_flex_params() {
use float_cmp::approx_eq;
use float_cmp::assert_approx_eq;
let params = FlexParams::new(0.0, None);
approx_eq!(f64, params.flex, 1.0, ulps = 2);
assert_approx_eq!(f64, params.flex, 1.0, ulps = 2);

let params = FlexParams::new(-0.0, None);
approx_eq!(f64, params.flex, 1.0, ulps = 2);
assert_approx_eq!(f64, params.flex, 1.0, ulps = 2);

let params = FlexParams::new(-1.0, None);
approx_eq!(f64, params.flex, 1.0, ulps = 2);
assert_approx_eq!(f64, params.flex, 1.0, ulps = 2);
}
}
8 changes: 4 additions & 4 deletions druid/src/widget/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ mod tests {
widget::{Container, Scroll},
WidgetExt, WidgetId,
};
use float_cmp::approx_eq;
use float_cmp::assert_approx_eq;

let id_1 = WidgetId::next();
let image_data = ImageBuf::from_raw(
Expand All @@ -445,7 +445,7 @@ mod tests {
harness.send_initial_events();
harness.just_layout();
let state = harness.get_state(id_1);
assert!(approx_eq!(f64, state.layout_rect().x1, 400.0));
assert_approx_eq!(f64, state.layout_rect().x1, 400.0);
})
}

Expand All @@ -456,7 +456,7 @@ mod tests {
widget::{Container, Scroll},
WidgetExt, WidgetId,
};
use float_cmp::approx_eq;
use float_cmp::assert_approx_eq;

let id_1 = WidgetId::next();
let image_data = ImageBuf::from_raw(
Expand All @@ -473,7 +473,7 @@ mod tests {
harness.send_initial_events();
harness.just_layout();
let state = harness.get_state(id_1);
assert!(approx_eq!(f64, state.layout_rect().x1, 400.0));
assert_approx_eq!(f64, state.layout_rect().x1, 400.0);
})
}

Expand Down

0 comments on commit 530dfc5

Please sign in to comment.