summaryrefslogtreecommitdiffstats
path: root/third_party/rust/uniffi-example-arithmetic/tests/bindings/test_arithmetic.rb
blob: 6669eb279f28cbe7d57d23c27b1d80371916a534 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

require 'test/unit'
require 'arithmetic'

include Test::Unit::Assertions

assert_raise Arithmetic::ArithmeticError::IntegerOverflow do
  Arithmetic.add 18_446_744_073_709_551_615, 1
end

assert_equal Arithmetic.add(2, 4), 6
assert_equal Arithmetic.add(4, 8), 12

assert_raise Arithmetic::ArithmeticError::IntegerOverflow do
  Arithmetic.sub 0, 1
end

assert_equal Arithmetic.sub(4, 2), 2
assert_equal Arithmetic.sub(8, 4), 4
assert_equal Arithmetic.div(8, 4), 2

assert_raise Arithmetic::InternalError do
  Arithmetic.div 8, 0
end

assert Arithmetic.equal(2, 2)
assert Arithmetic.equal(4, 4)

assert !Arithmetic.equal(2, 4)
assert !Arithmetic.equal(4, 8)