This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FizzBuzz <- function(M) | |
{ | |
for (intL in 1:M) | |
{ | |
if (intL %% 15 == 0) print("FizzBuzz") | |
else | |
if (intL %% 5 == 0) print("Buzz") | |
else | |
if (intL %% 3 == 0) print("Fizz") | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#presents_spec file | |
require './fizzbuzz_generator' | |
require './presents' | |
describe Presents, "#new" do | |
context 'as_text for output format' | |
it "returns fizzbuzz for numbers 1 through 15 in an array" do | |
p = Presents.new(FizzBuzzGenerator.new(15)) | |
p.as_text.should eq(["1 ","2 ","3 fizz ","4 ","5 buzz ","6 fizz ","7 ","8 ","9 fizz ","10 buzz ","11 ","12 fizz ","13 ","14 ","15 fizzbuzz "]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# FizzBuzz_Generator.rb | |
require 'json' | |
require 'rspec' | |
class FizzBuzzGenerator < Array | |
def initialize(high_value = 0) | |
@highest_value = high_value.to_i | |
# Error test | |
self << "Zero, negative numbers, strings that describe a number, and nil not supported" if (@highest_value <= 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "json" | |
class Presents < Struct.new(:ary) | |
def as_text | |
ary.each do |line| | |
puts line | |
end | |
end | |
def as_json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require './fizzbuzz_generator' | |
require './presents' | |
get '/' do | |
<<EOF | |
<html> | |
<body> | |
<h1>FizzBuzz!</h1> | |
<form method="post"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fizz buzz generator spec | |
require './fizzbuzz_generator' | |
describe FizzBuzzGenerator, "#new" do | |
context 'given 15 as an input' | |
it "returns fizzbuzz for numbers 1 through 15 in an array" do | |
fizzbuzz = FizzBuzzGenerator.new(15) | |
fizzbuzz.should eq(["1 ","2 ","3 fizz ","4 ","5 buzz ","6 fizz ","7 ","8 ","9 fizz ","10 buzz ","11 ","12 fizz ","13 ","14 ","15 fizzbuzz "]) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# FizzBuzz_Generator.rb | |
require 'json' | |
require 'rspec' | |
class FizzBuzzGenerator | |
def initialize(high_value = 0) | |
@highest_value = high_value.to_i | |
end | |
def generate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -wKU | |
require 'json' | |
require 'rspec' | |
class FizzBuzzGenerator | |
def initialize(inp) | |
@number = inp | |
end |