/**
@author CuiZhouwei
@date 2022/7/29
**/
package library
import (
"testing"
)
func TestOps(t *testing.T) {
mm := NewMusicManager()
if mm == nil {
t.Error("NewMusicManager failed")
}
if mm.Len() != 0{
t.Error("NewMusicManager falied,not empty.")
}
m0 := &Music{
Id: "1",
Name: "Take me to you heart",
Artist: "Mike",
Source: "http://qbox.me/2450123",
Type: "MP3",
}
m1 := &Music{
Id: "1",
Name: "Take me to you heart",
Artist: "Mike",
Source: "http://qbox.me/2450123",
Type: "MP3",
}
mm.Add(m0)
mm.Add(m1)
if mm.Len() != 2{
t.Error("MusicManager.Add() failed.")
}
_,m := mm.Find(m0.Name)
if m== nil{
t.Error("MusicManager.Find().")
}
if m.Id != m0.Id||m.Artist != m0.Artist ||
m.Type != m0.Type || m.Name != m0.Name ||m.Source != m0.Source{
t.Error("MusicManager.Find() failed.Found item mismatch.")
}
m ,err:= mm.Get(0)
if m== nil {
t.Error("MusicManger.Get() failed.",err)
}
m = mm.Remove(0)
if m == nil || mm.Len() != 1 {
t.Error("musicmanager.Remove failed.",err)
}
m = mm.RemoveByName(m0.Name)
if m == nil || mm.Len() != 0 {
t.Error("musicmanager.Remove failed.",err)
}
}