In reply to mavcdn:
The constraint
foreach (test_ones[i]) {if (i != 31) ( (test_ones[i] != test_ones[i+1]));}
means test_ones will have a repeating 2’b01 or 2’b10 pattern, and there will be 16 ones and 16 zeroes. That is in conflict with the other constraint
$countones(test_ones) == 12;
and so you get a constraint failure.