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

AdderTest.scala get a wrong testing #117

Open
citrus-lemon opened this issue Mar 20, 2018 · 1 comment
Open

AdderTest.scala get a wrong testing #117

citrus-lemon opened this issue Mar 20, 2018 · 1 comment

Comments

@citrus-lemon
Copy link

  for (t <- 0 until 4) {
    val rnd0 = rnd.nextInt(c.n)
    val rnd1 = rnd.nextInt(c.n)
    val rnd2 = rnd.nextInt(1)

    poke(c.io.A, rnd0)
    poke(c.io.B, rnd1)
    poke(c.io.Cin, rnd2)
    step(1)
    val rsum = rnd0 + rnd1 + rnd2
    val mask = BigInt("1"*c.n, 2)
    expect(c.io.Sum, rsum &  mask)
    expect(c.io.Cout, rsum % 1)
  }

rnd0, rnd1, rnd2 got a wrong number
rnd0 and rnd1 should be a random int with c.n bit, but this give 0 < x < c.n
rnd2 using val rnd2 = rnd.nextInt(1) always give 0

and the except io.Cout using rsum % 1 get always 0
because the rnd0 and rnd1 is too small, so the test always success

I suggest using

  for (t <- 0 until 4) {
    val rnd0 = rnd.nextInt(1<<c.n)
    val rnd1 = rnd.nextInt(1<<c.n)
    val rnd2 = rnd.nextInt(2)

    poke(c.io.A, rnd0)
    poke(c.io.B, rnd1)
    poke(c.io.Cin, rnd2)
    step(1)
    val rsum = rnd0 + rnd1 + rnd2
    val mask = BigInt("1"*c.n, 2)
    expect(c.io.Sum, rsum &  mask)
    expect(c.io.Cout, ((1 << c.n) & rsum) >> c.n)
  }
chick added a commit that referenced this issue Mar 20, 2018
Improved tests in accordance with suggestion by @lihanyuan
Bumped version dependencies in build.sbt
@chick
Copy link
Contributor

chick commented Mar 20, 2018

That's a good catch @WindProphet, thanks. I have submitted PR #118
which implements your suggestion. Please feel free to submit a PR for this
sort of thing. We welcome contributions.

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

2 participants