class Generator():
    def __init__(self, spec: Spec):
        self.foundry = Foundry(Optimize())
        self.foundry.applySpec(spec)
        self.spec = spec

    def createNew(self):
        try:
            pitches = self.foundry.extractPitches(self.spec.line)
        except Exception:
            return []
        self.foundry.apply(distinctFromExample(self.spec.line, [ConstPitch(x) for x in pitches]))
        return pitches
示例#2
0
def test_cfValidWorksOnInvalid(foundry, cantus, maxCount):
    badSpecs = getAllBadSpecs(cantus, maxCount)
    for badSpec in badSpecs:
        foundry = Foundry(Optimize()).applySpec(badSpec)
        cantus = foundry.extractPitches(badSpec.line)
        assert checkCF(cantus).isValid() == False
示例#3
0
def test_s3ValidWorksOnInvalidS3GoodCF(foundry, goodCF, s3GoodCF, s3MaxCounts):
    badSpecs = getAllBadSpecs(s3GoodCF, s3MaxCounts)
    for badSpec in badSpecs:
        foundry = Foundry(Optimize()).applySpec(badSpec)
        s3GoodCF = foundry.extractPitches(badSpec.line)
        assert checkS3(goodCF, s3GoodCF).isValid() == False
示例#4
0
def test_s2ValidWorksOnInvalidS2BadCF(foundry, badCF, s2BadCF, s2MaxCounts):
    badSpecs = getAllBadSpecs(s2BadCF, s2MaxCounts)
    for badSpec in badSpecs:
        foundry = Foundry(Optimize()).applySpec(badSpec)
        s2BadCF = foundry.extractPitches(badSpec.line)
        assert checkS2(badCF, s2BadCF).isValid() == False
示例#5
0
def test_s1ValidWorksOnInvalidS1BadCF(foundry, badCF, s1BadCF, maxCount):
    badSpecs = getAllBadSpecs(s1BadCF, maxCount)
    for badSpec in badSpecs:
        foundry = Foundry(Optimize()).applySpec(badSpec)
        s1BadCF = foundry.extractPitches(badSpec.line)
        assert checkS1(badCF, s1BadCF).isValid() == False
def test_repairS2WorksFromGoodCF(foundry, goodCF, s2GoodCF, s2MaxCounts, highSpeciesGamut):
    badSpecs = getAllBadSpecs(s2GoodCF, s2MaxCounts)
    for badSpec in badSpecs:
        foundry = Foundry(Optimize()).applySpec(badSpec)
        s2GoodCF = foundry.extractPitches(badSpec.line)
        assert checkS2(goodCF, repairS2(goodCF, s2GoodCF, highSpeciesGamut)).isValid() == True
def workingCF(cantus):
    f = Foundry(Optimize())
    f.applySpec(cantus)
    return f.extractPitches(cantus.line)
def test_repairS1WorksFromBadCF(foundry, badCF, s1BadCF, maxCount, highSpeciesGamut):
    badSpecs = getAllBadSpecs(s1BadCF, maxCount)
    for badSpec in badSpecs:
        foundry = Foundry(Optimize()).applySpec(badSpec)
        s1BadCF = foundry.extractPitches(badSpec.line)
        assert checkS1(badCF, repairS1(badCF, s1BadCF, highSpeciesGamut)).isValid() == True
def test_repairCFWorksOnBrokenCF(foundry, cantus, maxCount, cantusGamut):
    badSpecs = getAllBadSpecs(cantus, maxCount)
    for badSpec in badSpecs:
        foundry = Foundry(Optimize()).applySpec(badSpec)
        cantus = foundry.extractPitches(badSpec.line)
        assert checkCF(repairCF(cantus, cantusGamut)).isValid()