Skip to content

Instantly share code, notes, and snippets.

require 'test_helper'
class LightTest < ActiveSupport::TestCase
test 'arguments are valid' do
assert_raises(ArgumentError) { Light.new(:pink, :unbroken, Arc.new(0, 90)) }
assert_raises(ArgumentError) { Light.new(:white, :test, Arc.new(0, 90)) }
assert_raises(ArgumentError) { Light.new(:white, :unbroken, 10) }
assert_nothing_raised { Light.new(:white, :unbroken, Arc.new(0, 90)) }
end
@macuk
macuk / light.rb
Created September 10, 2020 07:47
class Light
COLORS = %i[white green red yellow].freeze
TYPES = %i[unbroken flashing].freeze
attr_reader :color, :type, :arc
def initialize(color, type, arc)
raise ArgumentError unless COLORS.include?(color)
raise ArgumentError unless TYPES.include?(type)
raise ArgumentError unless arc.is_a?(Arc)
require 'test_helper'
class ArcTest < ActiveSupport::TestCase
test 'arguments are valid' do
assert_raises(ArgumentError) { Arc.new(0, 400) }
assert_raises(ArgumentError) { Arc.new(-10, 200) }
assert_raises(ArgumentError) { Arc.new(0, 360) }
assert_nothing_raised { Arc.new(0, 90) }
end
@macuk
macuk / arc.rb
Created September 10, 2020 07:44
class Arc
def initialize(from, to)
raise ArgumentError if invalid?(from) || invalid?(to)
@from = from
@to = to
end
def to_s
"#{arc} degrees from #{@from} to #{@to}"
@macuk
macuk / phone2letters.rb
Last active August 29, 2015 13:59
Phone number to letters converter
Letters = {
'0' => %w(0),
'1' => %w(1),
'2' => %w(a b c),
'3' => %w(d e f),
'4' => %w(g h i),
'5' => %w(j k l),
'6' => %w(m n o),
'7' => %w(p q r s),
'8' => %w(t u v),
@macuk
macuk / mail-gem-problem.rb
Last active December 23, 2015 10:09
Mail gem problem
# - Konfeo.com
# - Mail wysyłany jako organizator
# - ~ 15 000 wysyłanych maili miesięcznie
# ------------------------------------------------------------
# Kodowanie nagłówków maili
require 'mail'
m = Mail.new