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

randsz_list_t: Placing the sum constraint before the size constraints can result in incorrect sums [v0.8.8] #204

Open
alwilson opened this issue Feb 5, 2024 · 0 comments

Comments

@alwilson
Copy link
Contributor

alwilson commented Feb 5, 2024

Calling the sum constraint after the size constraints seems to work well, which I think is due to the size being solved in a RandSet before the sum RandSet. Calling the sum constraint before appears to use the previous or initialized (maximum?) size of the randsz_list_t.

This runs til the sum isn't correct:

import vsc

@vsc.randobj
class my_cls(object):

    def __init__(self):
        self.l = vsc.randsz_list_t(vsc.uint8_t())

    @vsc.constraint
    def l_c(self):
        self.l.sum == 10
        self.l.size > 0
        self.l.size <= 5

my_i : vsc.RandObjInt = my_cls()
for _ in range(100):
    my_i.randomize(debug=False)
    print(f'{len(my_i.l)=} {my_i.l}')
    if sum(my_i.l) != 10:
        break

Output:

len(my_i.l)=5 [0, 8, 1, 0, 1]
len(my_i.l)=5 [0, 0, 0, 0, 10]
len(my_i.l)=2 [8, 0]
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

No branches or pull requests

1 participant