Skip to content

Commit

Permalink
symbol to string
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanlas committed Jul 18, 2024
1 parent 10763ff commit ae3cfa9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ class PackageSpec extends Specification {
"prevent side-effects on subsequent applications" in {
val scratch = collection.mutable.Map[Symbol, Int]().withDefaultValue(0)

val originalFunction = { key: Symbol =>
val originalFunction = { key: String =>
scratch(key) = scratch(key) + 1
}

val memoizedFunction = memoize(originalFunction)

memoizedFunction('pauper)
scratch === Map('pauper -> 1)
memoizedFunction("pauper")
scratch === Map("pauper" -> 1)

memoizedFunction('pauper)
scratch === Map('pauper -> 1)
memoizedFunction("pauper")
scratch === Map("pauper" -> 1)

originalFunction('prince)
originalFunction('prince)
scratch == Map('pauper -> 1, 'prince -> 2) // smart equality operator not so smart on disparate constructions?
originalFunction("prince")
originalFunction("prince")
scratch == Map("pauper" -> 1, "prince" -> 2) // smart equality operator not so smart on disparate constructions?
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SolverSpec extends Specification {
def randomIndex(size: Int) = iterator.next()
}

randomIndividual(Seq('arthas))(rig) === 'arthas
randomIndividual(Seq("arthas"))(rig) === "arthas"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ class DiscreteAlleleGeneratorSpec extends Specification {
"A discrete allele generator" should {
"return the expected values" in {

val generator = new DiscreteAlleleGenerator[Symbol] with AlleleIndexProvider {
val generator = new DiscreteAlleleGenerator[String] with AlleleIndexProvider {
private val rng = Iterable(2, 0, 1).iterator

val alleles = Seq('alpha, 'beta, 'gamma)
val alleles = Seq("alpha", "beta", "gamma")

def nextAlleleIndex(size: Int) = rng.next()
}

generator.generateAllele === 'gamma
generator.generateAllele === 'alpha
generator.generateAllele === 'beta
generator.generateAllele === "gamma"
generator.generateAllele === "alpha"
generator.generateAllele === "beta"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ class FixedLengthCombinatorSpec extends Specification {
}

"generate the expected values" in {
firstChromosome === Seq('luigi, 'bowser, 'peach)
secondChromosome === Seq('mario, 'luigi, 'bowser)
firstChromosome === Seq("luigi", "bowser", "peach")
secondChromosome === Seq("mario", "luigi", "bowser")
}

"support spot mutation" in {
mutatedChromosome === Seq('luigi, 'mario, 'peach)
mutatedChromosome === Seq("luigi", "mario", "peach")
}

"support crossover" in {
combinator.crossover(firstChromosome, secondChromosome) === Seq('mario, 'luigi, 'peach)
combinator.crossover(firstChromosome, secondChromosome) === Seq("mario", "luigi", "peach")
}
}
}

class FixedTestCombinator(val size: Int) extends FixedLengthCombinator[Symbol] with DiscreteAlleleGenerator[Symbol] {
class FixedTestCombinator(val size: Int) extends FixedLengthCombinator[String] with DiscreteAlleleGenerator[String] {
private val alleleIndexes = Iterable(1, 3, 2, 0, 1, 3, 0).iterator
private val parents = Iterable(false, false, true).iterator

def alleles: Seq[Symbol] = Seq('mario, 'luigi, 'peach, 'bowser)
def alleles: Seq[String] = Seq("mario", "luigi", "peach", "bowser")

def nextAlleleIndex(size: Int) = alleleIndexes.next()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@ class VariableLengthCombinatorSpec extends Specification {
}

"generate chromosomes of the provided alleles" in {
firstChromosome === Seq('GoGo)
secondChromosome === Seq('HoneyLemon, 'Baymax, 'Fred)
thirdChromosome === Seq('Hiro, 'Wasabi, 'GoGo, 'Baymax, 'HoneyLemon)
firstChromosome === Seq("GoGo")
secondChromosome === Seq("HoneyLemon", "Baymax", "Fred")
thirdChromosome === Seq("Hiro", "Wasabi", "GoGo", "Baymax", "HoneyLemon")
}

"support spot mutation" in {
secondMutation === Seq('HoneyLemon, 'Hiro, 'Fred)
secondMutation === Seq("HoneyLemon", "Hiro", "Fred")
}

"support insertion mutation" in {
thirdMutation === Seq('Wasabi, 'Hiro, 'Wasabi, 'GoGo, 'Baymax, 'HoneyLemon)
thirdMutation === Seq("Wasabi", "Hiro", "Wasabi", "GoGo", "Baymax", "HoneyLemon")
}

"support removal mutation" in {
firstMutation === Seq.empty
}

"support crossover" in {
child === Seq('GoGo, 'Fred)
child === Seq("GoGo", "Fred")
}
}
}

class VariableTestCombinator extends VariableLengthCombinator[Symbol] with DiscreteAlleleGenerator[Symbol] {
class VariableTestCombinator extends VariableLengthCombinator[String] with DiscreteAlleleGenerator[String] {
val initialSize = 11
val alleles = Seq('Hiro, 'Baymax, 'Fred, 'GoGo, 'Wasabi, 'HoneyLemon)
val alleles = Seq("Hiro", "Baymax", "Fred", "GoGo", "Wasabi", "HoneyLemon")

private val mutationMethods =
Iterable(RemoveGene, MutateGene, AddGene).iterator
Expand Down

0 comments on commit ae3cfa9

Please sign in to comment.