Skip to content

Commit 5c0d951

Browse files
Cynthia RichCynthia Rich
authored andcommitted
add tests for travis
1 parent f99c721 commit 5c0d951

File tree

7 files changed

+231
-0
lines changed

7 files changed

+231
-0
lines changed

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: ruby
2+
rvm:
3+
- 2.1
4+
install:
5+
- npm install
6+
- bundle install
7+
8+
script:
9+
# Line 11 introduces a pre-existing linter test to the code.
10+
# Feel free to uncomment if you're curious about what this looks like!
11+
# - npm test
12+
- ruby tests/test_verifyurl.rb

script/check-remotes

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
# setup environment
6+
export PATH="/usr/share/rbenv/shims:$PATH"
7+
8+
echo "hostname: $(hostname)"
9+
echo "pwd: $(pwd)"
10+
git --version
11+
12+
# store remotes in variable
13+
CURRENT_REMOTES=$(git remote -v)
14+
15+
# print out the remote information
16+
echo $CURRENT_REMOTES
17+
18+
# set URL stored for origin to ORIGIN variable
19+
ORIGIN=$(git config remote.origin.url)
20+
21+
# set URL for upstream to UPSTREAM variable
22+
UPSTREAM=$(git config remote.upstream.url)
23+
24+
# set origin length
25+
ORIGIN_LENGTH=${#ORIGIN}
26+
27+
# set length of output to size variable
28+
CURRENT_LENGTH=${#CURRENT_REMOTES}
29+
30+
# set desired length by using remote url
31+
DESIRED_LENGTH=$(($ORIGIN_LENGTH + $ORIGIN_LENGTH + 161))
32+
33+
if [ $UPSTREAM = 'https://github.com/githubschool/github-games.git' ]
34+
then
35+
echo "The upstream is GitHubSchool/GitHubGames!"
36+
else
37+
echo "The upstream is incorrect."
38+
exit 1
39+
fi
40+
41+
42+
if [ $DESIRED_LENGTH -eq $CURRENT_LENGTH ]
43+
then
44+
echo "You have an upstream remote set."
45+
else
46+
echo "You do not have an upstream remote set."
47+
exit 1
48+
fi
49+
50+
51+
exit 0

tests/test_differentcolors.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
require 'test/unit'
2+
3+
class TestDifferentColors < Test::Unit::TestCase
4+
5+
def test_different_colors
6+
#open file and read
7+
file = File.read('./index.html')
8+
9+
# search for color pieces
10+
color_i_index = file.index('var i')
11+
color_j_index = file.index('var j')
12+
color_l_index = file.index('var l')
13+
color_o_index = file.index('var o')
14+
color_s_index = file.index('var s')
15+
color_t_index = file.index('var t')
16+
color_z_index = file.index('var z')
17+
last_index = file.index('do the bit manipulation')
18+
19+
color_i = file[color_i_index + 69...color_j_index - 11]
20+
puts color_i
21+
22+
color_j = file[color_j_index + 69...color_l_index - 11]
23+
puts color_j
24+
25+
color_l = file[color_l_index + 69...color_o_index - 9]
26+
puts color_l
27+
28+
color_o = file[color_o_index + 69...color_s_index - 9]
29+
puts color_o
30+
31+
color_s = file[color_s_index + 69...color_t_index - 10]
32+
puts color_s
33+
34+
color_t = file[color_t_index + 69...color_z_index - 9]
35+
puts color_t
36+
37+
color_z = file[color_z_index + 69...last_index - 71]
38+
puts color_z
39+
40+
# compare all pieces
41+
42+
color_array = [color_i, color_j, color_l, color_o, color_s, color_t, color_z]
43+
puts color_array.uniq == color_array
44+
45+
assert(color_array.uniq == color_array, "You have multiple pieces with the same color!")
46+
end
47+
48+
end

tests/test_speeddecrement.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require 'test/unit'
2+
3+
class TestGameDecrement < Test::Unit::TestCase
4+
5+
def test_game_decrement
6+
# open file to read
7+
file = File.read('./index.html')
8+
9+
# search for decrement word
10+
decrement_index = file.index('decrement')
11+
min_index = file.index('min:')
12+
puts decrement_index
13+
puts '> '
14+
puts min_index
15+
16+
# assign number after decrement to a variable
17+
decrement = file[decrement_index + 11...min_index - 2]
18+
puts decrement
19+
20+
decrement_less_than_1 = decrement.to_f < 1.0
21+
decrement_greater_than_0 = decrement.to_f > 0.0
22+
# assert if that variable is between 0-1
23+
assert(decrement_less_than_1, "The rate of decrement is too high! Bring 'decrement' above 0 and below 1.")
24+
assert(decrement_greater_than_0, "The rate of decrement is too slow. Bring 'decrement' above 0 and below 1.")
25+
end
26+
27+
end

tests/test_speedmax.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require 'test/unit'
2+
3+
class TestGameSpeedMax < Test::Unit::TestCase
4+
5+
def test_game_speed_max
6+
# open file to read
7+
file = File.read('./index.html')
8+
9+
# search for decrement word
10+
min_index = file.index('min:')
11+
end_index = file.index('}, // how long')
12+
puts min_index
13+
puts '> '
14+
puts end_index
15+
16+
# assign number after decrement to a variable
17+
min = file[min_index + 5 ...end_index]
18+
19+
puts min
20+
21+
min_less_than_1 = min.to_f < 1.0
22+
min_greater_than_0 = min.to_f > 0.0
23+
# assert if that variable is between 0-1
24+
assert(min_less_than_1, "The speed is too high! Bring 'min' above 0 and below 1.")
25+
assert(min_greater_than_0, "The speed too slow. Bring 'min' above 0 and below 1.")
26+
end
27+
28+
end

tests/test_speedstart.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require 'test/unit'
2+
3+
class TestGameStart < Test::Unit::TestCase
4+
5+
def test_game_start
6+
# open file to read
7+
file = File.read('./index.html')
8+
9+
# search for decrement word
10+
start_index = file.index('start:')
11+
decrement_index = file.index('decrement:')
12+
puts start_index
13+
puts '> '
14+
puts decrement_index
15+
16+
# assign number after decrement to a variable
17+
start = file[start_index + 7...decrement_index - 2]
18+
19+
puts start
20+
21+
start_less_than_1 = start.to_f < 1.0
22+
start_greater_than_0 = start.to_f > 0.0
23+
# assert if that variable is between 0-1
24+
assert(start_less_than_1, "The start speed is too high! Bring it above 0 and below 1.")
25+
assert(start_greater_than_0, "The start speed too slow. Bring it above 0 and below 1.")
26+
end
27+
28+
end

tests/test_verifyurl.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require 'test/unit'
2+
3+
class TestGameStart < Test::Unit::TestCase
4+
5+
def test_game_start
6+
# open file to read
7+
file = File.read('./README.md')
8+
9+
# get url for remote
10+
remote = `git config remote.origin.url`
11+
12+
# get username in remote url
13+
split_remote = remote.to_s.split('/')
14+
username_remote = split_remote[4]
15+
username_remote.delete!("\n")
16+
user_remote_split = username_remote.to_s.split('.')
17+
user_remote = user_remote_split[0]
18+
print 'Username in remote: '
19+
puts user_remote
20+
21+
# search for README url, assign to link
22+
link_index = file.index('at:')
23+
link_end_index = file.index('>> _*SUP')
24+
link = file[link_index + 4...link_end_index - 3]
25+
26+
# get username from link in readme
27+
split_readme = link.to_s.split('/')
28+
username_readme = split_readme[3]
29+
print 'Username in README: '
30+
puts username_readme
31+
32+
33+
# compare those strings, pass test if they're equal
34+
assert_equal(user_remote, username_readme, "The URL to the game in the README.md doesn't match the username in the remote repository.")
35+
end
36+
37+
end

0 commit comments

Comments
 (0)