Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing random mutant-selection #31

Merged
merged 10 commits into from
Nov 23, 2023

Conversation

DurieuxPol
Copy link
Collaborator

@DurieuxPol DurieuxPol commented Nov 14, 2023

Added a random mutant-selection decorator. It decorates a mutations-generation strategy and it randomly selects a mutant among all mutants generated.
Also added two types of concrete random mutant-selectors.
The first one randomly selects a fixed number of distinct mutants (FixedRandomMutantSelection), while the second one selects a percentage of them (PercentRandomMutantSelection).

An example of how to use it:
image

@DurieuxPol
Copy link
Collaborator Author

DurieuxPol commented Nov 16, 2023

Implemented another type of random selection.
Rather than selecting a random mutant among all the mutants generated, it selects a random mutation operator, then it selects a random mutant among the mutants generated with the chosen operator.
It exists in both forms as well, using a fixed number of mutants (FixedRandomOperatorMutantSelection) or a percentage of all mutants (PercentRandomOperatorMutantSelection).

1 to: numberOfMutants do: [ :i |
operator := operators at:
(random nextIntegerBetween: 1 and: operators size).
[ (dict at: operator) allSatisfy: [ :each | newColl includes: each ] ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice check! but it would be nice it comes with a comment :)

It's important to understand that if you already selected all the mutants in an operator, then you need to filter the operator out, otherwise this will loop forever looking for mutants (and they are all used)

whileTrue: [
operator := operators at:
(random nextIntegerBetween: 1 and: operators size) ].
size := (dict at: operator) size.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like the same code as above. How can we enhance it a bit and avoid the repeated code?

size := aCollection size.
newColl := aCollection copyEmpty.
random := Random new.
numberOfMutants := size * percentageOfMutants / 100.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, so you transformed a percentage into an absolute number of mutants.
Now you can reuse the code from the other class!! How could you do it? :)

dict := aCollection groupedBy: [ :e | e operator ].
operators := dict keys.
1 to: numberOfMutants do: [ :i |
operator := operators at:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here!

Copy link
Contributor

@guillep guillep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Pol! I think the code is good, but we could do a pass before integration because there is no rush ^^

@DurieuxPol
Copy link
Collaborator Author

I did some refactoring.
Now RandomOperatorMutantSelection is a decorator as well, decorating a RandomMutantSelection, and it changes only the way mutants are selected. This allowed a lot of code not to be repeated.
Also updated the tests.

RandomOperatorMutantSelection percent: is similar to the old PercentRandomOperatorMutantSelection new percentageOfMutants:, and RandomOperatorMutantSelection fixed: to FixedRandomOperatorMutantSelection new numberOfMutants: .

An example:
image

Copy link
Contributor

@guillep guillep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better! I think there are still duplications we can remove and simplify, let's discuss them later.

Thanks @DurieuxPol !

@guillep guillep merged commit 9ead243 into pharo-contributions:master Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants