Sha256: 378eb564a8f8e743d6ab795dcbddc377e6b1f723394f60cb3b6f5d6572909ac2
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
require "test_helper" module Whitespace::ISA describe Mod do before do @vm = Whitespace::VM.new end describe "#execute" do describe "when the value stack is empty" do it "raises Whitespace::EmptyError" do expect(@vm.vstack.size).must_equal 0 expect { Mod.new(@vm).execute }.must_raise Whitespace::EmptyError end end describe "when the value stack has one element" do it "raises Whitespace::EmptyError" do @vm.vstack.push 1 expect(@vm.vstack.size).must_equal 1 expect { Mod.new(@vm).execute }.must_raise Whitespace::EmptyError end end describe "when the value stack has at least 2 elements" do it "replaces the top 2 elements with their remainder" do @vm.vstack.push 1 @vm.vstack.push 5 @vm.vstack.push 3 expect(@vm.vstack.size).must_equal 3 Mod.new(@vm).execute expect(@vm.vstack.pop).must_equal 2 expect(@vm.vstack.pop).must_equal 1 expect(@vm.vstack.size).must_equal 0 end end describe "modulo 0" do it "raises ZeroDivisionError" do @vm.vstack.push 1 @vm.vstack.push 0 expect { Mod.new(@vm).execute }.must_raise ZeroDivisionError end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
whitespace-ruby-1.0.0 | test/whitespace/instructions/arithmetic/mod_test.rb |