tudortimi / constraints

Reusable constraints
Apache License 2.0
3 stars 1 forks source link

Add standard constraints to classes #7

Open tudortimi opened 2 years ago

tudortimi commented 2 years ago

It is often very useful to constraint fields of classes to be equal to a value or in a certain range, as well as the opposites of the previous two. These can be provided by the library:

class some_class;

  rand int some_int_field;
  rand some_enum_e some_enum_field;

  `constraints_infrastructure_begin(some_class)
    `constraints_field(int, some_field)
    `constraints_field(some_enum_e, some_enum_field)
  `constraints_infrastructure_end

endclass

This would define the following factory methods:

some_class::standard_constraints::on_some_int_field::only(10);
some_class::standard_constraints::on_some_int_field::never(42);
some_class::standard_constraints::on_some_int_field::any_of('{  1, 10, 100 });
some_class::standard_constraints::on_some_int_field::none_of('{  -1, -10, -100 });

and the same for some_enum_field.