Consolidate completely stateless tests into doctests
Removing dupes
This commit is contained in:
@@ -16,6 +16,44 @@ defmodule MusicBrainz.ReleaseSearchResult do
|
||||
}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the physical format of a release based on its media.
|
||||
|
||||
Returns `:multi` when a release contains different format types.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> MusicBrainz.ReleaseSearchResult.format(%MusicBrainz.ReleaseSearchResult{
|
||||
...> id: "1", title: "T", release_group: nil, artists: "A", date: "2000", barcode: "0",
|
||||
...> media: [%{format: "CD", disc_count: 1, track_count: 11}]
|
||||
...> })
|
||||
:cd
|
||||
|
||||
iex> MusicBrainz.ReleaseSearchResult.format(%MusicBrainz.ReleaseSearchResult{
|
||||
...> id: "1", title: "T", release_group: nil, artists: "A", date: "2000", barcode: "0",
|
||||
...> media: [%{format: "12\\" Vinyl", disc_count: 0, track_count: 8}]
|
||||
...> })
|
||||
:vinyl
|
||||
|
||||
iex> MusicBrainz.ReleaseSearchResult.format(%MusicBrainz.ReleaseSearchResult{
|
||||
...> id: "1", title: "T", release_group: nil, artists: "A", date: "2000", barcode: "0",
|
||||
...> media: [
|
||||
...> %{format: "CD", disc_count: 1, track_count: 10},
|
||||
...> %{format: "CD", disc_count: 1, track_count: 9}
|
||||
...> ]
|
||||
...> })
|
||||
:cd
|
||||
|
||||
iex> MusicBrainz.ReleaseSearchResult.format(%MusicBrainz.ReleaseSearchResult{
|
||||
...> id: "1", title: "T", release_group: nil, artists: "A", date: "2000", barcode: "0",
|
||||
...> media: [
|
||||
...> %{format: "CD", disc_count: 0, track_count: 11},
|
||||
...> %{format: "DVD-Video", disc_count: 0, track_count: 22}
|
||||
...> ]
|
||||
...> })
|
||||
:multi
|
||||
|
||||
"""
|
||||
def format(release_search_result) do
|
||||
sorted_frequencies =
|
||||
release_search_result.media
|
||||
|
||||
@@ -276,12 +276,45 @@ defmodule MusicLibrary.Country do
|
||||
iex> MusicLibrary.Country.to_emoji("US")
|
||||
"🇺🇸"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("PL")
|
||||
"🇵🇱"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("GB")
|
||||
"🇬🇧"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("us")
|
||||
"🇺🇸"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("pl")
|
||||
"🇵🇱"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("GB-SCT")
|
||||
"🏴"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("GB-WLS")
|
||||
"🏴"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("GB-ENG")
|
||||
"🏴"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("GB-CYM") == MusicLibrary.Country.to_emoji("GB-WLS")
|
||||
true
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("USA")
|
||||
"🇺🇸"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("GBR")
|
||||
"🇬🇧"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("POL")
|
||||
"🇵🇱"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("en-US")
|
||||
"🇺🇸"
|
||||
|
||||
iex> MusicLibrary.Country.to_emoji("pl-PL")
|
||||
"🇵🇱"
|
||||
|
||||
"""
|
||||
@spec to_emoji(String.t()) :: String.t()
|
||||
def to_emoji(code) when is_binary(code) do
|
||||
|
||||
@@ -1,4 +1,26 @@
|
||||
defmodule MusicLibraryWeb.Duration do
|
||||
@moduledoc """
|
||||
Formats durations from milliseconds to human-readable strings.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Formats a duration in milliseconds as a human-readable string.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> MusicLibraryWeb.Duration.format_duration(30_000)
|
||||
"0:30"
|
||||
|
||||
iex> MusicLibraryWeb.Duration.format_duration(90_000)
|
||||
"1:30"
|
||||
|
||||
iex> MusicLibraryWeb.Duration.format_duration(3_723_000)
|
||||
"1:02:03"
|
||||
|
||||
iex> MusicLibraryWeb.Duration.format_duration(0)
|
||||
"0:00"
|
||||
|
||||
"""
|
||||
def format_duration(milliseconds) do
|
||||
milliseconds
|
||||
|> System.convert_time_unit(:millisecond, :second)
|
||||
|
||||
Reference in New Issue
Block a user