Skip to content

Commit

Permalink
Tests for const int cast.
Browse files Browse the repository at this point in the history
  • Loading branch information
markkurossi committed Dec 10, 2023
1 parent 2fbb188 commit f540fb3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
9 changes: 9 additions & 0 deletions compiler/tests/const_cast_int_0.mpcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// -*- go -*-

package main

// @Test 42 1 = -1
func main(a, b uint64) int {
val := int32(0x7fffffff)
return int16(val)
}
9 changes: 9 additions & 0 deletions compiler/tests/const_cast_int_1.mpcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// -*- go -*-

package main

// Test 42 1 = 65535
func main(a, b uint64) uint {
val := uint32(0xffffffff)
return uint16(val)
}
File renamed without changes.
12 changes: 10 additions & 2 deletions compiler/testsuite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/markkurossi/mpc/circuit"
"github.com/markkurossi/mpc/compiler/utils"
"github.com/markkurossi/mpc/types"
)

const (
Expand Down Expand Up @@ -154,13 +155,20 @@ loop:
continue loop
}
for idx, result := range results {
out := circ.Outputs[idx]
bits := int(out.Type.Bits)
if out.Type.Type == types.TInt && result.Bit(bits-1) == 1 {
// Negative number.
tmp := new(big.Int)
tmp.SetBit(tmp, bits, 1)
result.Sub(tmp, result)
result.Neg(result)
}
if result.Cmp(outputs[idx]) != 0 {
t.Errorf("%s: result %d mismatch: got %v, expected %v",
file, idx, result.Text(base), outputs[idx].Text(base))
}
}

_ = results
}
if cpuprof {
pprof.StopCPUProfile()
Expand Down

0 comments on commit f540fb3

Please sign in to comment.