<commit_before>#!/usr/bin/env python
"""Unit Tests for the Music Summaries code."""

import librosa
import numpy as np
import os
import six
import sys

from nose.tools import eq_, raises
from scipy.io import wavfile

sys.path.append("..")
import main
import utils

AUDIO_DIR = os.path.join("..", "audio")


def test_synth_summary():
    # Get audio
    audio_file = os.path.join(AUDIO_DIR, "mindless.ogg")
    features, audio = main.compute_features(audio_file, main.PCP_TYPE)

    # Generate random summary
    summary_idxs = [0, 16, 32]
    N = 16
    summary = main.synth_summary(audio, features["beats"], summary_idxs, N,
                                 fade=0)

    # Check that it is correct
    start_sample = utils.time_to_sample(features["beats"][summary_idxs[0]],
                                        sr=main.SAMPLING_RATE)
    for i, summary_sample in enumerate(summary):
        assert np.isclose(audio[start_sample + i], summary_sample)

    # Save file
    wavfile.write("out_sum.wav", main.SAMPLING_RATE, summary)

    # Try with other fades
    summary = main.synth_summary(audio, features["beats"], summary_idxs, N,
                                 fade=8)


def test_find_optimal_summary():
    P = 3
    N = 5
    L = int(N / 2)
    M = 30
    n_features = 12
    sequence = np.arange(M * n_features).reshape(M, n_features)
    #sequence = np.random.random((M, n_features))
    main.find_optimal_summary(sequence, P, N, L=L)

def test_disjoint_information():
    L = 3
    N = 10
    summary = []
    summary.append(np.zeros(N).reshape(N, 1))
    summary.append(np.ones(N).reshape(N, 1))
    disjoint = main.compute_disjoint_information(summary, L=L)
    assert np.isclose(disjoint, 1.0)

    L = 4
    N = 100
    summary = []<commit_msg>Cleaned up test code<commit_after>#!/usr/bin/env python
"""Unit Tests for the Music Summaries code."""

import numpy as np
import os
import six
import sys

from nose.tools import eq_, raises
from scipy.io import wavfile

sys.path.append("..")
import main
import utils

AUDIO_DIR = os.path.join("..", "audio")


def test_synth_summary():
    # Get audio
    audio_file = os.path.join(AUDIO_DIR, "mindless.ogg")
    features, audio = main.compute_features(audio_file, main.PCP_TYPE)

    # Generate random summary
    summary_idxs = [0, 16, 32]
    N = 16
    summary = main.synth_summary(audio, features["beats"], summary_idxs, N,
                                 fade=0)

    # Check that it is correct
    start_sample = utils.time_to_sample(features["beats"][summary_idxs[0]],
                                        sr=main.SAMPLING_RATE)
    for i, summary_sample in enumerate(summary):
        assert np.isclose(audio[start_sample + i], summary_sample)

    # Save file
    wavfile.write("out_sum.wav", main.SAMPLING_RATE, summary)

    # Try with other fades
    summary = main.synth_summary(audio, features["beats"], summary_idxs, N,
                                 fade=8)


def test_find_optimal_summary():
    P = 3
    N = 5
    L = int(N / 2)
    M = 30
    n_features = 12
    sequence = np.arange(M * n_features).reshape(M, n_features)
    #sequence = np.random.random((M, n_features))
    main.find_optimal_summary(sequence, P, N, L=L)


def test_disjoint_information():
    L = 3
    N = 10
    summary = []
    summary.append(np.zeros(N).reshape(N, 1))
    summary.append(np.ones(N).reshape(N, 1))
    disjoint = main.compute_disjoint_information(summary, L=L)
    assert np.isclose(disjoint, 1.0)

    L = 4
    N = 100
    summary = []
{'fraction_non_alphanumeric': 0.11885129371623543, 'fraction_numerical': 0.01592266135911288, 'mean_word_length': 2.7227513227513227, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2052639', 'n_tokens_mistral': 1247, 'n_tokens_neox': 1175, 'n_words': 285}