Ejemplo n.º 1
0
    def test_good_rules():
        parncutt = Parncutt()
        parncutt.segment_combiner(method="cost")

        for id in subcosts:
            d_corpus = DCorpus(corpus_str=TestConstant.PARNCUTT_HUMAN_FRAGMENT[id])
            parncutt.load_corpus(d_corpus=d_corpus)
            if id == 'B':
                suggestions, costs, details = parncutt.generate_advice(staff="upper", cycle=4, k=20)
            else:
                suggestions, costs, details = parncutt.generate_advice(staff="upper", last_digit=last_digit[id], k=30)
            details_for_sugg = dict()
            for i in range(len(details)):
                details_for_sugg[suggestions[i]] = details[i][0]  # 0 index because we only have one segment

            # parncutt.report_on_advice(suggestions, costs, details)
            for gold_sugg in subcosts[id]:
                assert gold_sugg in details_for_sugg, \
                    "Missing suggestion {0} in {1}".format(gold_sugg, id)
                for rule in subcosts[id][gold_sugg]:
                    # if rule == 'bl1':
                        # continue
                    gold_cost = subcosts[id][gold_sugg][rule]
                    cost = details_for_sugg[gold_sugg][rule]
                    assert cost == gold_cost, \
                        "Bad {0} cost for {1} in {2}: {3} should be {4}".format(rule, gold_sugg, id, cost, gold_cost)
Ejemplo n.º 2
0
 def test_fingering_counts():
     parncutt = Parncutt(pruning_method="none")
     parncutt.segment_combiner(method="cost")
     d_corpus = DCorpus(corpus_str=TestConstant.FOUR_NOTES)
     parncutt.load_corpus(d_corpus=d_corpus)
     suggestions, costs, details = parncutt.generate_advice(staff="upper", k=2)
     assert parncutt.last_segment_pruned_count() == 320, "Bad none pruning on open-ended problem"
Ejemplo n.º 3
0
 def test_cycles():
     parncutt = Parncutt()
     parncutt.segment_combiner(method="cost")
     d_corpus = DCorpus(corpus_str=TestConstant.FOUR_NOTES)
     parncutt.load_corpus(d_corpus=d_corpus)
     suggestions, costs, details = parncutt.generate_advice(staff="upper", cycle=4, k=2)
     assert len(suggestions) == 2, "No loops in that dog in top ten"
     # parncutt.report_on_advice(suggestions, costs, details)
     d_corpus = DCorpus(corpus_str=TestConstant.PARNCUTT_HUMAN_FRAGMENT['B'])
     parncutt.load_corpus(d_corpus=d_corpus)
     suggestions, costs, details = parncutt.generate_advice(staff="upper", cycle=4, k=16)
     assert len(suggestions) == 16, "There should be 16 cyclic fingerings!"
Ejemplo n.º 4
0
    def test_bl1():
        parncutt = Parncutt()
        parncutt.segment_combiner(method="cost")
        midi_1 = None
        handed_digit_1 = '-'
        midi_2 = 61
        handed_digit_2 = '>1'
        midi_3 = 65
        handed_digit_3 = '>3'

        trigram_node = TrigramNode(midi_1, handed_digit_1, midi_2, handed_digit_2, midi_3, handed_digit_3)
        cost, costs = parncutt.trigram_node_cost(trigram_node)
        assert costs['bl1'] == 3, "Bad bl1 cost"
Ejemplo n.º 5
0
    def test_sma_lar():
        parncutt = Parncutt()
        parncutt.segment_combiner(method="cost")

        for id in sma_lar_sums:
            d_corpus = DCorpus(corpus_str=TestConstant.PARNCUTT_HUMAN_FRAGMENT[id])
            parncutt.load_corpus(d_corpus=d_corpus)
            if id == 'B':
                suggestions, costs, details = parncutt.generate_advice(staff="upper", cycle=4, k=20)
            else:
                suggestions, costs, details = parncutt.generate_advice(staff="upper", last_digit=last_digit[id], k=20)
            details_for_sugg = dict()
            for i in range(len(details)):
                details_for_sugg[suggestions[i]] = details[i][0]  # 0 index because we only have one segment

            # parncutt.report_on_advice(suggestions, costs, details)
            for gold_sugg in sma_lar_sums[id]:
                assert gold_sugg in details_for_sugg,\
                    "Missing suggestion {0} in {1}".format(gold_sugg, id)
                sma = details_for_sugg[gold_sugg]['sma']
                lar = details_for_sugg[gold_sugg]['lar']
                assert sma + lar == sma_lar_sums[id][gold_sugg],\
                    "Bad sma + lar total for {0} in {1}".format(gold_sugg, id)