2222import static com .code_intelligence .jazzer .mutation .support .TypeSupport .withExtraAnnotations ;
2323import static com .code_intelligence .jazzer .mutation .utils .PropertyConstraint .DECLARATION ;
2424import static com .google .common .truth .Truth .assertThat ;
25+ import static org .junit .jupiter .api .Assertions .assertThrows ;
2526
2627import com .code_intelligence .jazzer .mutation .annotation .ValuePool ;
2728import java .io .IOException ;
@@ -89,6 +90,45 @@ void testExtractFirstProbability_TwoWithLastUsed() {
8990 assertThat (p ).isEqualTo (0.2 );
9091 }
9192
93+ @ Test
94+ void testExtractFirstMaxMutations_Default () {
95+ AnnotatedType type = new TypeHolder <@ ValuePool ("myPool" ) String >() {}.annotatedType ();
96+ int maxMutations = valuePools .extractFirstMaxMutations (type );
97+ assertThat (maxMutations ).isEqualTo (1 );
98+ }
99+
100+ @ Test
101+ void testExtractFirstMaxMutations_OneUserDefined () {
102+ AnnotatedType type =
103+ new TypeHolder <
104+ @ ValuePool (value = "myPool2" , maxMutations = 10 ) String >() {}.annotatedType ();
105+ int maxMutations = valuePools .extractFirstMaxMutations (type );
106+ assertThat (maxMutations ).isEqualTo (10 );
107+ }
108+
109+ @ Test
110+ void testExtractMaxMutations_TwoWithLastUsed () {
111+ AnnotatedType type =
112+ withExtraAnnotations (
113+ new TypeHolder <
114+ @ ValuePool (value = "myPool" , maxMutations = 2 ) String >() {}.annotatedType (),
115+ new ValuePoolBuilder ().value ("myPool2" ).maxMutations (10 ).build ());
116+ int maxMutations = valuePools .extractFirstMaxMutations (type );
117+ assertThat (maxMutations ).isEqualTo (2 );
118+ }
119+
120+ @ Test
121+ void testExtractFirstMaxMutations_Negative () {
122+ AnnotatedType type =
123+ new TypeHolder <
124+ @ ValuePool (value = "myPool2" , maxMutations = -1 ) String >() {}.annotatedType ();
125+ assertThat (
126+ assertThrows (
127+ IllegalArgumentException .class , () -> valuePools .extractFirstMaxMutations (type )))
128+ .hasMessageThat ()
129+ .contains ("@ValuePool maxMutations must be >= 0" );
130+ }
131+
92132 @ Test
93133 void testExtractRawValues_OneAnnotation () {
94134 AnnotatedType type = new TypeHolder <@ ValuePool ("myPool" ) String >() {}.annotatedType ();
@@ -353,13 +393,15 @@ private static class ValuePoolBuilder {
353393 private String [] value ;
354394 private String [] files ;
355395 private double p ;
396+ private int maxMutations ;
356397 private String constraint ;
357398
358399 public ValuePoolBuilder () {
359400 try {
360401 value = (String []) getDefault ("value" );
361402 files = (String []) getDefault ("files" );
362403 p = (double ) getDefault ("p" );
404+ maxMutations = (int ) getDefault ("maxMutations" );
363405 constraint = (String ) getDefault ("constraint" );
364406 } catch (NoSuchMethodException e ) {
365407 throw new RuntimeException ("Could not load ValuePool defaults" , e );
@@ -385,6 +427,11 @@ public ValuePoolBuilder p(double p) {
385427 return this ;
386428 }
387429
430+ public ValuePoolBuilder maxMutations (int maxMutations ) {
431+ this .maxMutations = maxMutations ;
432+ return this ;
433+ }
434+
388435 public ValuePoolBuilder constraint (String constraint ) {
389436 this .constraint = constraint ;
390437 return this ;
@@ -393,6 +440,7 @@ public ValuePoolBuilder constraint(String constraint) {
393440 public ValuePool build () {
394441 final String [] value = this .value ;
395442 final double p = this .p ;
443+ final int maxMutations = this .maxMutations ;
396444 final String constraint = this .constraint ;
397445
398446 return new ValuePool () {
@@ -416,6 +464,11 @@ public double p() {
416464 return p ;
417465 }
418466
467+ @ Override
468+ public int maxMutations () {
469+ return maxMutations ;
470+ }
471+
419472 @ Override
420473 public String constraint () {
421474 return constraint ;
@@ -430,13 +483,18 @@ public boolean equals(Object o) {
430483 return Arrays .equals (this .value (), other .value ())
431484 && Arrays .equals (this .files (), other .files ())
432485 && this .p () == other .p ()
486+ && this .maxMutations () == other .maxMutations ()
433487 && this .constraint ().equals (other .constraint ());
434488 }
435489
436490 @ Override
437491 public int hashCode () {
438492 return Objects .hash (
439- Arrays .hashCode (value ()), Arrays .hashCode (files ()), p (), constraint ());
493+ Arrays .hashCode (value ()),
494+ Arrays .hashCode (files ()),
495+ p (),
496+ maxMutations (),
497+ constraint ());
440498 }
441499
442500 @ Override
@@ -449,6 +507,8 @@ public String toString() {
449507 + String .join (", " , files ())
450508 + "}, p="
451509 + p ()
510+ + ", maxMutations="
511+ + maxMutations ()
452512 + ", constraint="
453513 + constraint ()
454514 + ")" ;
0 commit comments