@@ -11,6 +11,8 @@ import com.adamratzman.spotify.utils.Locale
1111import com.adamratzman.spotify.utils.Market
1212import com.adamratzman.spotify.utils.getCurrentTimeMs
1313import kotlin.test.Test
14+ import kotlin.test.assertEquals
15+ import kotlin.test.assertNotEquals
1416import kotlin.test.assertNotNull
1517import kotlin.test.assertNotSame
1618import kotlin.test.assertTrue
@@ -37,8 +39,8 @@ class BrowseApiTest {
3739 if (! testPrereq()) return @runBlockingTest
3840
3941 assertNotSame(
40- api.browse.getCategoryList(locale = Locale .ar_AE).items[0 ],
41- api.browse.getCategoryList().items[0 ]
42+ api.browse.getCategoryList(locale = Locale .ar_AE).items[0 ],
43+ api.browse.getCategoryList().items[0 ]
4244 )
4345 assertTrue(api.browse.getCategoryList(4 , 3 , market = Market .CA ).items.isNotEmpty())
4446 assertTrue(api.browse.getCategoryList(4 , 3 , locale = Locale .fr_FR, market = Market .CA ).items.isNotEmpty())
@@ -62,7 +64,12 @@ class BrowseApiTest {
6264 runBlockingTest {
6365 if (! testPrereq()) return @runBlockingTest
6466
65- assertFailsWithSuspend<SpotifyException .BadRequestException > { api.browse.getPlaylistsForCategory(" no u" , limit = 4 ) }
67+ assertFailsWithSuspend<SpotifyException .BadRequestException > {
68+ api.browse.getPlaylistsForCategory(
69+ " no u" ,
70+ limit = 4
71+ )
72+ }
6673 assertTrue(api.browse.getPlaylistsForCategory(" pop" , 10 , 0 , Market .FR ).items.isNotEmpty())
6774 }
6875 }
@@ -73,12 +80,12 @@ class BrowseApiTest {
7380 if (! testPrereq()) return @runBlockingTest
7481
7582 assertTrue(
76- api.browse.getFeaturedPlaylists(
77- 5 ,
78- 4 ,
79- market = Market .US ,
80- timestamp = getCurrentTimeMs() - 10000000
81- ).playlists.total > 0
83+ api.browse.getFeaturedPlaylists(
84+ 5 ,
85+ 4 ,
86+ market = Market .US ,
87+ timestamp = getCurrentTimeMs() - 10000000
88+ ).playlists.total > 0
8289 )
8390 assertTrue(api.browse.getFeaturedPlaylists(offset = 32 ).playlists.total > 0 )
8491 }
@@ -107,102 +114,114 @@ class BrowseApiTest {
107114 }
108115 assertTrue(api.browse.getTrackRecommendations(seedArtists = listOf (" 2C2sVVXanbOpymYBMpsi89" )).tracks.isNotEmpty())
109116 assertTrue(
110- api.browse.getTrackRecommendations(
111- seedArtists = listOf (
112- " 2C2sVVXanbOpymYBMpsi89" ,
113- " 7lMgpN1tEBQKpRoUMKB8iw"
114- )
115- ).tracks.isNotEmpty()
117+ api.browse.getTrackRecommendations(
118+ seedArtists = listOf (
119+ " 2C2sVVXanbOpymYBMpsi89" ,
120+ " 7lMgpN1tEBQKpRoUMKB8iw"
121+ )
122+ ).tracks.isNotEmpty()
116123 )
117124
118125 assertFailsWithSuspend<SpotifyException .BadRequestException > {
119126 api.browse.getTrackRecommendations(seedTracks = listOf (" abc" ))
120127 }
121128 assertTrue(api.browse.getTrackRecommendations(seedTracks = listOf (" 3Uyt0WO3wOopnUBCe9BaXl" )).tracks.isNotEmpty())
122129 assertTrue(
123- api.browse.getTrackRecommendations(
124- seedTracks = listOf (
125- " 6d9iYQG2JvTTEgcndW81lt" ,
126- " 3Uyt0WO3wOopnUBCe9BaXl"
127- )
128- ).tracks.isNotEmpty()
130+ api.browse.getTrackRecommendations(
131+ seedTracks = listOf (
132+ " 6d9iYQG2JvTTEgcndW81lt" ,
133+ " 3Uyt0WO3wOopnUBCe9BaXl"
134+ )
135+ ).tracks.isNotEmpty()
129136 )
130137
131138 api.browse.getTrackRecommendations(seedGenres = listOf (" abc" ))
132139 assertTrue(api.browse.getTrackRecommendations(seedGenres = listOf (" pop" )).tracks.isNotEmpty())
133140 assertTrue(
134- api.browse.getTrackRecommendations(
135- seedGenres = listOf (
136- " pop" ,
137- " latinx"
138- )
139- ).tracks.isNotEmpty()
141+ api.browse.getTrackRecommendations(
142+ seedGenres = listOf (
143+ " pop" ,
144+ " latinx"
145+ )
146+ ).tracks.isNotEmpty()
140147 )
141148
142149 api.browse.getTrackRecommendations(
143- seedArtists = listOf (" 2C2sVVXanbOpymYBMpsi89" ),
144- seedTracks = listOf (" 6d9iYQG2JvTTEgcndW81lt" , " 3Uyt0WO3wOopnUBCe9BaXl" ),
145- seedGenres = listOf (" pop" )
150+ seedArtists = listOf (" 2C2sVVXanbOpymYBMpsi89" ),
151+ seedTracks = listOf (" 6d9iYQG2JvTTEgcndW81lt" , " 3Uyt0WO3wOopnUBCe9BaXl" ),
152+ seedGenres = listOf (" pop" )
146153 )
147154
148155 assertFailsWithSuspend<IllegalArgumentException > {
149156 api.browse.getTrackRecommendations(
150- targetAttributes = listOf (
151- TuneableTrackAttribute .Acousticness .asTrackAttribute(
152- 3f
153- )
157+ targetAttributes = listOf (
158+ TuneableTrackAttribute .Acousticness .asTrackAttribute(
159+ 3f
154160 )
161+ )
155162 )
156163 }
157164 assertTrue(
158- api.browse.getTrackRecommendations(
159- targetAttributes = listOf (
160- TuneableTrackAttribute .Acousticness .asTrackAttribute(1f ),
161- TuneableTrackAttribute .Danceability .asTrackAttribute(0.5f )
162- ),
163- seedGenres = listOf (" pop" )
164- ).tracks.isNotEmpty()
165+ api.browse.getTrackRecommendations(
166+ targetAttributes = listOf (
167+ TuneableTrackAttribute .Acousticness .asTrackAttribute(1f ),
168+ TuneableTrackAttribute .Danceability .asTrackAttribute(0.5f )
169+ ),
170+ seedGenres = listOf (" pop" )
171+ ).tracks.isNotEmpty()
165172 )
166173
167174 assertFailsWithSuspend<IllegalArgumentException > {
168175 api.browse.getTrackRecommendations(
169- minAttributes = listOf (
170- TuneableTrackAttribute .Acousticness .asTrackAttribute(
171- 3f
172- )
176+ minAttributes = listOf (
177+ TuneableTrackAttribute .Acousticness .asTrackAttribute(
178+ 3f
173179 )
180+ )
174181 )
175182 }
176183 assertTrue(
177- api.browse.getTrackRecommendations(
178- minAttributes = listOf (
179- TuneableTrackAttribute .Acousticness .asTrackAttribute(0.5f ),
180- TuneableTrackAttribute .Danceability .asTrackAttribute(0.5f )
181- ),
182- seedGenres = listOf (" pop" )
183- ).tracks.isNotEmpty()
184+ api.browse.getTrackRecommendations(
185+ minAttributes = listOf (
186+ TuneableTrackAttribute .Acousticness .asTrackAttribute(0.5f ),
187+ TuneableTrackAttribute .Danceability .asTrackAttribute(0.5f )
188+ ),
189+ seedGenres = listOf (" pop" )
190+ ).tracks.isNotEmpty()
184191 )
185192
186193 assertFailsWithSuspend<SpotifyException .BadRequestException > {
187194 api.browse.getTrackRecommendations(
188- maxAttributes = listOf (
189- TuneableTrackAttribute .Speechiness .asTrackAttribute(
190- 0.9f
191- )
195+ maxAttributes = listOf (
196+ TuneableTrackAttribute .Speechiness .asTrackAttribute(
197+ 0.9f
192198 )
199+ )
193200 )
194201 }
195202 assertTrue(
196- api.browse.getTrackRecommendations(
197- maxAttributes = listOf (
198- TuneableTrackAttribute .Acousticness .asTrackAttribute(0.9f ),
199- TuneableTrackAttribute .Danceability .asTrackAttribute(0.9f )
200- ),
201- seedGenres = listOf (" pop" )
202- ).tracks.isNotEmpty()
203+ api.browse.getTrackRecommendations(
204+ maxAttributes = listOf (
205+ TuneableTrackAttribute .Acousticness .asTrackAttribute(0.9f ),
206+ TuneableTrackAttribute .Danceability .asTrackAttribute(0.9f )
207+ ),
208+ seedGenres = listOf (" pop" )
209+ ).tracks.isNotEmpty()
203210 )
204211
205212 assertTrue(TuneableTrackAttribute .values().first().asTrackAttribute(0f ).value == 0f )
206213 }
207214 }
215+
216+ @Test
217+ fun testTuneableTrackAttributeTypes () {
218+ val float1: TuneableTrackAttribute <* > = TuneableTrackAttribute .Speechiness
219+ val float2: TuneableTrackAttribute <* > = TuneableTrackAttribute .Acousticness
220+ val int1: TuneableTrackAttribute <* > = TuneableTrackAttribute .Key
221+ val int2: TuneableTrackAttribute <* > = TuneableTrackAttribute .Popularity
222+
223+ assertEquals(float1.typeClass, float2.typeClass)
224+ assertEquals(int1.typeClass, int2.typeClass)
225+ assertNotEquals(float1.typeClass, int1.typeClass)
226+ }
208227}
0 commit comments