<commit_before>﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Synth;
using System.Collections.Generic;
using System.Threading;
using Rationals;
using Akka.Actor;

namespace Test
{
    [TestClass]
    public class SongTest
    {
        [TestMethod]
        public void MaryHadALittleLamb()
        {
            using (var hub = new AudioHub())
            {
                IActorRef leftSpeaker = hub.NewSpeaker();
                var song = new Song();
                song.Tempo = 120;
                var notes = new List<Note>
                {
                    new Note(NoteName.E, 1),
                    new Note(NoteName.D, 1),
                    new Note(NoteName.C, (Rational)1/3),
                    new Note(NoteName.B, (Rational)1/3),
                    new Note(NoteName.C, (Rational)1/3),
                    new Note(NoteName.D, 1),
                    new Note(NoteName.E, 1),
                    new Note(NoteName.E, 1),
                    new Note(NoteName.E, 2)
                };
                song.AddTrack(0, notes);

                var otherNotes = new List<Note>
                {
                    new Note(NoteName.G, 2),
                    new Note(NoteName.A, 2).OctaveUp,
                    new Note(NoteName.G, 4)
                };
                song.AddTrack(1, otherNotes);

                var numBeats = 8;
                var beatTime = (int)Math.Round(1000 / (song.Tempo / 60.0));
                leftSpeaker.Tell(song);
                Thread.Sleep(numBeats * beatTime);
            }
        }

        [TestMethod]
        public void TrackWithRests()
        {
            using (var hub = new AudioHub())
            {
                IActorRef leftSpeaker = hub.NewSpeaker();
                var song = new Song();
                song.Tempo = 120;
                var notes = new List<Note>
                {
                    new Note(NoteName.E, 1),
                    new Note(NoteName.Rest, 1),
                    new Note(NoteName.D, 1),
                    new Note(NoteName.Rest, 1),
                    new Note(NoteName.C, 4),
                };
                song.AddTrack(0, notes);

                var numBeats = 8;
                var beatTime = (int)Math.Round(1000 / (song.Tempo / 60.0));
                leftSpeaker.Tell(song);
                Thread.Sleep(numBeats * beatTime);
            }
        }

        [TestMethod]
        public void SyncopationTest()
        {
            using (var hub = new AudioHub())
            {
                IActorRef leftSpeaker = hub.NewSpeaker();
                var song = new Song();
                song.Tempo = 120;
                var notes = new List<Note>
                {
                    new Note(NoteName.E, (Rational)3/2),
                    new Note(NoteName.E, 1),
                    new Note(NoteName.E, 1),
                    new Note(NoteName.E, (Rational)1/4),
                    new Note(NoteName.E, (Rational)1/4),
                    new Note(NoteName.E, (Rational)1/2)
                };
                song.AddTrack(0, notes);

                var numBeats = 5;
                var beatTime = (int)Math.Round(1000 / (song.Tempo / 60.0));
                leftSpeaker.Tell(song);
                Thread.Sleep(numBeats * beatTime);
            }
        }
    }
}
<commit_msg>DRY up song initialization<commit_after>﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Synth;
using System.Collections.Generic;
using System.Threading;
using Rationals;
using Akka.Actor;

namespace Test
{
    [TestClass]
    public class SongTest
    {
        [TestMethod]
        public void MaryHadALittleLamb()
        {
            InitializeSong(120, (song, speaker) =>
            {
                var notes = new List<Note>
                {
                    new Note(NoteName.E, 1),
                    new Note(NoteName.D, 1),
                    new Note(NoteName.C, (Rational)1/3),
                    new Note(NoteName.B, (Rational)1/3),
                    new Note(NoteName.C, (Rational)1/3),
                    new Note(NoteName.D, 1),
                    new Note(NoteName.E, 1),
                    new Note(NoteName.E, 1),
                    new Note(NoteName.E, 2)
                };
                song.AddTrack(0, notes);

                var otherNotes = new List<Note>
                {
                    new Note(NoteName.G, 2),
                    new Note(NoteName.A, 2).OctaveUp,
                    new Note(NoteName.G, 4)
                };
                song.AddTrack(1, otherNotes);

                var numBeats = 8;
                var beatTime = (int)Math.Round(1000 / (song.Tempo / 60.0));
                speaker.Tell(song);
                Thread.Sleep(numBeats * beatTime);
            });
        }

        [TestMethod]
        public void TrackWithRests()
        {
            InitializeSong(120, (song, speaker) =>
            {
                var notes = new List<Note>
                {
                    new Note(NoteName.E, 1),
                    new Note(NoteName.Rest, 1),
                    new Note(NoteName.D, 1),
                    new Note(NoteName.Rest, 1),
                    new Note(NoteName.C, 4),
                };
                song.AddTrack(0, notes);

                var numBeats = 8;
                var beatTime = (int)Math.Round(1000 / (song.Tempo / 60.0));
                speaker.Tell(song);
                Thread.Sleep(numBeats * beatTime);
            });
        }

        [TestMethod]
        public void SyncopationTest()
        {
            InitializeSong(120, (song, speaker) =>
            {
                var notes = new List<Note>
                {
                    new Note(NoteName.E, (Rational)3/2),
                    new Note(NoteName.E, 1),
                    new Note(NoteName.E, 1),
                    new Note(NoteName.E, (Rational)1/4),
                    new Note(NoteName.E, (Rational)1/4),
                    new Note(NoteName.E, (Rational)1/2)
                };
                song.AddTrack(0, notes);

                var numBeats = 5;
                var beatTime = (int)Math.Round(1000 / (song.Tempo / 60.0));
                speaker.Tell(song);
                Thread.Sleep(numBeats * beatTime);
            });
        }

        private void InitializeSong(int tempo, Action<Song, IActorRef> block)
        {
            using (var hub = new AudioHub())
            {
                IActorRef speaker = hub.NewSpeaker();
                var song = new Song();
                song.Tempo = 120;
                block(song, speaker);
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.10542844324809332, 'fraction_numerical': 0.020487513085090475, 'mean_word_length': 1.105793450881612, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1253012', 'n_tokens_mistral': 2049, 'n_tokens_neox': 1797, 'n_words': 393}