<commit_before>package main

import (
	"reflect"
	"testing"
)

func TestInit(t *testing.T) {
	cases := []struct {
		before *Playlist
		want   *Playlist
	}{
		{
			InitPlaylist(),
			&Playlist{
				[]*PlaylistItem{},
				-1,
			},
		},
	}

	for _, c := range cases {
		if !reflect.DeepEqual(c.before, c.want) {
			t.Errorf("TestInit: %q != %q", c.before, c.want)
		}
	}
}

func TestEnqueue(t *testing.T) {
	cases := []struct {
		before      *Playlist
		item        *PlaylistItem
		index       int
		want        *Playlist
		shoulderror bool
	}{
		{
			InitPlaylist(),
			&PlaylistItem{"/Music/theballadofbilbobaggins.mp3", "aaa", true},
			0,
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"/Music/theballadofbilbobaggins.mp3", "aaa", true},
				},
				-1,
			},
			false,
		},
		// Test invalid index
		{
			InitPlaylist(),
			&PlaylistItem{"/Music/iamlordeyayaya.wav", "aaa", true},
			1,
			&Playlist{
				[]*PlaylistItem{},
				-1,
			},
			true,
		},
		// Test hash collision
		{
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"I am lorde ya ya ya", "aaa", true},
				},
				-1,
			},
			&PlaylistItem{"I too am lorde", "aaa", true},
			1,
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"I am lorde ya ya ya", "aaa", true},
				},
				-1,
			},
			true,
		},
	}

	for caseno, c := range cases {
		_, err := c.before.Enqueue(c.index, c.item)
		if c.shoulderror != (err != nil) {
			if err != nil {
				t.Errorf("TestEnqueue: case %d returned err when should be nil(%s)", caseno, err.Error())
			} else {
				t.Errorf("TestEnqueue: case %d returned nil when should be err", caseno)
			}
		}
		if !reflect.DeepEqual(c.before, c.want) {
			t.Errorf("TestEnqueue: %q != %q", c.before, c.want)
		}
	}
}

func TestDequeue(t *testing.T) {
	cases := []struct {
		before      *Playlist
		index       int
		hash        string
		want        *Playlist
		shoulderror bool
	}{
		// Test dequeue
		{
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"darude - sandstorm.avi", "a1", true},
				},
				-1,
			},
			0,
			"a1",
			&Playlist{
				[]*PlaylistItem{},
				-1,
			},
			false,
		},
		// Test dequeue empty
		{
			InitPlaylist(),
			0,
			"yayaya",
			&Playlist{
				[]*PlaylistItem{},
				-1,
			},
			true,
		},
		// Test mismatching index and hash
		{
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"a_walk_in_the_black_forest.ogg", "a1", true},
					&PlaylistItem{"cactus_in_my_yfronts.mid", "b2", true},
				},
				-1,
			},
			0,
			"b2",
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"a_walk_in_the_black_forest.ogg", "a1", true},
					&PlaylistItem{"cactus_in_my_yfronts.mid", "b2", true},
				},
				-1,
			},
			true,
		},
		// Test invalid index
		{
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"a_walk_in_the_black_forest.ogg", "a1", true},
					&PlaylistItem{"cactus_in_my_yfronts.mid", "b2", true},
				},
				-1,
			},
			1337,
			"b2",
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"a_walk_in_the_black_forest.ogg", "a1", true},
					&PlaylistItem{"cactus_in_my_yfronts.mid", "b2", true},
				},
				-1,
			},
			true,
		},
		// Test invalid hash
		{
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"a_walk_in_the_black_forest.ogg", "a1", true},
					&PlaylistItem{"cactus_in_my_yfronts.mid", "b2", true},
				},
				-1,
			},
			0,
			"c3",
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"a_walk_in_the_black_forest.ogg", "a1", true},
					&PlaylistItem{"cactus_in_my_yfronts.mid", "b2", true},
				},
				-1,
			},
			true,
		},
	}

	for caseno, c := range cases {
		_, _, err := c.before.Dequeue(c.index, c.hash)
		if c.shoulderror != (err != nil) {
			if err != nil {
				t.Errorf("TestEnqueue: case %d returned err when should be nil(%s)", caseno, err.Error())
			} else {
				t.Errorf("TestEnqueue: case %d returned nil when should be err", caseno)
			}<commit_msg>Add testing for selection being adjusted<commit_after>package main

import (
	"reflect"
	"testing"
)

func TestInit(t *testing.T) {
	cases := []struct {
		before *Playlist
		want   *Playlist
	}{
		{
			InitPlaylist(),
			&Playlist{
				[]*PlaylistItem{},
				-1,
			},
		},
	}

	for _, c := range cases {
		if !reflect.DeepEqual(c.before, c.want) {
			t.Errorf("TestInit: %q != %q", c.before, c.want)
		}
	}
}

func TestEnqueue(t *testing.T) {
	cases := []struct {
		before      *Playlist
		item        *PlaylistItem
		index       int
		want        *Playlist
		shoulderror bool
	}{
		{
			InitPlaylist(),
			&PlaylistItem{"/Music/theballadofbilbobaggins.mp3", "aaa", true},
			0,
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"/Music/theballadofbilbobaggins.mp3", "aaa", true},
				},
				-1,
			},
			false,
		},
		// Test invalid index
		{
			InitPlaylist(),
			&PlaylistItem{"/Music/iamlordeyayaya.wav", "aaa", true},
			1,
			&Playlist{
				[]*PlaylistItem{},
				-1,
			},
			true,
		},
		// Test hash collision
		{
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"I am lorde ya ya ya", "aaa", true},
				},
				-1,
			},
			&PlaylistItem{"I too am lorde", "aaa", true},
			1,
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"I am lorde ya ya ya", "aaa", true},
				},
				-1,
			},
			true,
		},
		// Test selection adjustment
		{
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"iamlorde.m4a", "ya", true},
				},
				0,
			},
			&PlaylistItem{"iamsparticus.flac", "hurr", true},
			0,
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"iamsparticus.flac", "hurr", true},
					&PlaylistItem{"iamlorde.m4a", "ya", true},
				},
				1, // Selection should have been adjusted, we enqueued before the selection
			},
			false,
		},
	}

	for caseno, c := range cases {
		_, err := c.before.Enqueue(c.index, c.item)
		if c.shoulderror != (err != nil) {
			if err != nil {
				t.Errorf("TestEnqueue: case %d returned err when should be nil(%s)", caseno, err.Error())
			} else {
				t.Errorf("TestEnqueue: case %d returned nil when should be err", caseno)
			}
		}
		if !reflect.DeepEqual(c.before, c.want) {
			t.Errorf("TestEnqueue: %q != %q", c.before, c.want)
		}
	}
}

func TestDequeue(t *testing.T) {
	cases := []struct {
		before      *Playlist
		index       int
		hash        string
		want        *Playlist
		shoulderror bool
	}{
		// Test dequeue. NB, selection should reset to -1
		{
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"darude - sandstorm.avi", "a1", true},
				},
				0,
			},
			0,
			"a1",
			&Playlist{
				[]*PlaylistItem{},
				-1,
			},
			false,
		},
		// Test dequeue empty
		{
			InitPlaylist(),
			0,
			"yayaya",
			&Playlist{
				[]*PlaylistItem{},
				-1,
			},
			true,
		},
		// Test mismatching index and hash
		{
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"a_walk_in_the_black_forest.ogg", "a1", true},
					&PlaylistItem{"cactus_in_my_yfronts.mid", "b2", true},
				},
				-1,
			},
			0,
			"b2",
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"a_walk_in_the_black_forest.ogg", "a1", true},
					&PlaylistItem{"cactus_in_my_yfronts.mid", "b2", true},
				},
				-1,
			},
			true,
		},
		// Test invalid index
		{
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"a_walk_in_the_black_forest.ogg", "a1", true},
					&PlaylistItem{"cactus_in_my_yfronts.mid", "b2", true},
				},
				-1,
			},
			1337,
			"b2",
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"a_walk_in_the_black_forest.ogg", "a1", true},
					&PlaylistItem{"cactus_in_my_yfronts.mid", "b2", true},
				},
				-1,
			},
			true,
		},
		// Test invalid hash
		{
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"a_walk_in_the_black_forest.ogg", "a1", true},
					&PlaylistItem{"cactus_in_my_yfronts.mid", "b2", true},
				},
				-1,
			},
			0,
			"c3",
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"a_walk_in_the_black_forest.ogg", "a1", true},
					&PlaylistItem{"cactus_in_my_yfronts.mid", "b2", true},
				},
				-1,
			},
			true,
		},
		// Test selection adjustment
		{
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"a_walk_in_the_black_forest.ogg", "a1", true},
					&PlaylistItem{"cactus_in_my_yfronts.mid", "b2", true},
				},
				1,
			},
			0,
			"a1",
			&Playlist{
				[]*PlaylistItem{
					&PlaylistItem{"cactus_in_my_yfronts.mid", "b2", true},
				},
				0,
			},
			false,
		},
	}

	for caseno, c := range cases {
		_, _, err := c.before.Dequeue(c.index, c.hash)
		if c.shoulderror != (err != nil) {
			if err != nil {
				t.Errorf("TestEnqueue: case %d returned err when should be nil(%s)", caseno, err.Error())
			} else {
				t.Errorf("TestEnqueue: case %d returned nil when should be err", caseno)
			}
{'fraction_non_alphanumeric': 0.174953314659197, 'fraction_numerical': 0.011788048552754435, 'mean_word_length': 2.5541269182911654, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '182106', 'n_tokens_mistral': 4327, 'n_tokens_neox': 3449, 'n_words': 661}