From d347d89dfeef54d648ffdea054897617c0016509 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 6 Jun 2026 19:48:22 +0300 Subject: correctly working auto completion for db --- tests/daemon.rs | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tests/daemon.rs (limited to 'tests/daemon.rs') diff --git a/tests/daemon.rs b/tests/daemon.rs new file mode 100644 index 0000000..e5cb270 --- /dev/null +++ b/tests/daemon.rs @@ -0,0 +1,79 @@ +/* + * This file is a part of RSPlayer + * Licensed under the GPL-3.0 License + * Copyright (C) 2026 Salmonik @ salmonik@tuta.io + * https://codeberg.org/salmonik/RSPlayer +*/ + +use std::path::PathBuf; + +use rsp::daemon::ScrobbleState; +use rsp::queue::Track; + +#[test] +fn test_scrobble_state_new() { + let s = ScrobbleState::new(); + assert!(s.track.is_none()); + assert!(s.start_time.is_none()); + assert!(s.timestamp.is_none()); +} + +#[test] +fn test_scrobble_state_clear() { + let mut s = ScrobbleState::new(); + let t = Track { + path: PathBuf::from("/test/song.mp3"), + title: Some("Test".into()), + artist: Some("Artist".into()), + album: None, + duration_secs: Some(200.0), + is_stream: false, + }; + s.start(t); + assert!(s.track.is_some()); + s.clear(); + assert!(s.track.is_none()); + assert!(s.start_time.is_none()); + assert!(s.timestamp.is_none()); +} + +#[test] +fn test_should_scrobble_without_track_returns_false() { + assert!(!ScrobbleState::new().should_scrobble()); +} + +#[test] +fn test_should_scrobble_threshold_below_30_seconds() { + assert!(!ScrobbleState::should_scrobble_with_params(29, Some(200.0))); +} + +#[test] +fn test_should_scrobble_threshold_half_duration() { + assert!(ScrobbleState::should_scrobble_with_params(100, Some(200.0))); +} + +#[test] +fn test_should_scrobble_threshold_below_half_duration() { + assert!(!ScrobbleState::should_scrobble_with_params(80, Some(200.0))); +} + +#[test] +fn test_should_scrobble_threshold_capped_at_4min() { + assert!(ScrobbleState::should_scrobble_with_params(240, Some(600.0))); + assert!(!ScrobbleState::should_scrobble_with_params( + 239, + Some(600.0) + )); +} + +#[test] +fn test_should_scrobble_no_duration_requires_4min() { + assert!(ScrobbleState::should_scrobble_with_params(240, None)); + assert!(!ScrobbleState::should_scrobble_with_params(239, None)); +} + +#[test] +fn test_should_scrobble_short_song() { + assert!(ScrobbleState::should_scrobble_with_params(30, Some(60.0))); + assert!(!ScrobbleState::should_scrobble_with_params(15, Some(60.0))); +} -- cgit v1.2.3