Skip to content

Commit

Permalink
Switch create to use create2() on client-side tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JonJagger committed Aug 21, 2021
1 parent 6eedb3a commit 265f085
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 223 deletions.
21 changes: 0 additions & 21 deletions client/source/external/custom_start_points.rb

This file was deleted.

21 changes: 0 additions & 21 deletions client/source/external/exercises_start_points.rb

This file was deleted.

21 changes: 0 additions & 21 deletions client/source/external/languages_start_points.rb

This file was deleted.

30 changes: 4 additions & 26 deletions client/source/external/saver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,8 @@ def ready?

# - - - - - - - - - - - - - - - - - - -

def group_create_custom(version, display_name)
@http.post(__method__, {
version:version,
display_name:display_name
})
end

def group_create(version, ltf_name, exercise_name)
@http.post(__method__, {
version:version,
ltf_name:ltf_name,
exercise_name:exercise_name
})
def group_create(manifest)
@http.post(__method__, { manifest:manifest })
end

def group_exists?(id)
Expand All @@ -53,19 +42,8 @@ def group_fork(id, index)

# - - - - - - - - - - - - - - - - - - -

def kata_create_custom(version, display_name)
@http.post(__method__, {
version:version,
display_name:display_name
})
end

def kata_create(version, ltf_name, exercise_name)
@http.post(__method__, {
version:version,
ltf_name:ltf_name,
exercise_name:exercise_name
})
def kata_create(manifest)
@http.post(__method__, { manifest:manifest })
end

def kata_exists?(id)
Expand Down
15 changes: 0 additions & 15 deletions client/source/externals.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
require_relative 'external/custom_start_points'
require_relative 'external/exercises_start_points'
require_relative 'external/languages_start_points'
require_relative 'external/http'
require_relative 'external/saver'

class Externals

def custom_start_points
@custom_start_points ||= External::CustomStartPoints.new
end

def exercises_start_points
@exercises_start_points ||= External::ExercisesStartPoints.new
end

def languages_start_points
@languages_start_points ||= External::LanguagesStartPoints.new
end

def saver
@saver ||= External::Saver.new(http)
end
Expand Down
6 changes: 3 additions & 3 deletions client/test/config/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

code: {
lines: {
total:173,
missed:0,
total:169,
missed:18,
},
branches: {
total:2,
Expand All @@ -24,7 +24,7 @@

test: {
lines: {
total:647,
total:593,
missed:0,
},
branches: {
Expand Down
42 changes: 2 additions & 40 deletions client/test/create_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,73 +8,35 @@ def self.id58_prefix

# - - - - - - - - - - - - - - - - -

versions_test 'q31', %w(
|POST /group_create_custom()
|has status 200
|returns the id: of a new group
|that exists in saver
|whose manifest matches
) do
in_group_custom do |id, display_name|
assert group_exists?(id), :group_exists?
m = group_manifest(id)
assert_equal id, m['id'], :id
assert_equal version, m['version'], :version
assert_equal display_name, m['display_name'], :display_name
assert_equal '', m['exercise'], :no_exercise
end
end

versions_test 'q32', %w(
|POST /group_create()
|has status 200
|returns the id: of a new group
|that exists in saver
|whose manifest matches
) do
in_group do |id, ltf_name, exercise_name|
in_group do |id|
assert group_exists?(id), :group_exists?
m = group_manifest(id)
assert_equal id, m['id'], :id
assert_equal version, m['version'], :version
assert_equal ltf_name, m['display_name'], :display_name
assert_equal exercise_name, m['exercise'], :exercise
end
end

# - - - - - - - - - - - - - - - - -

versions_test 'q33', %w(
|POST /kata_create_custom()
|has status 200
|returns the id: of a new kata
|that exists in saver
|whose manifest matches
) do
in_kata_custom do |id, display_name|
assert kata_exists?(id), :group_exists?
m = kata_manifest(id)
assert_equal id, m['id'], :id
assert_equal version, m['version'], :version
assert_equal display_name, m['display_name'], :display_name
assert_equal '', m['exercise'], :no_exercise
end
end

versions_test 'q34', %w(
|POST /kata_create()
|has status 200
|returns the id: of a new kata
|that exists in saver
|whose manifest matches
) do
in_kata do |id, ltf_name, exercise_name|
in_kata do |id|
assert kata_exists?(id), :group_exists?
m = kata_manifest(id)
assert_equal id, m['id'], :id
assert_equal version, m['version'], :version
assert_equal ltf_name, m['display_name'], :display_name
assert_equal exercise_name, m['exercise'], :exercise
end
end

Expand Down
3 changes: 0 additions & 3 deletions client/test/group_exists_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ def self.id58_prefix
in_group do |id|
assert group_exists?(id), :in_group
end
in_group_custom do |id|
assert group_exists?(id), :in_group_custom
end
end

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
3 changes: 0 additions & 3 deletions client/test/group_join_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ def self.id58_prefix
in_group do |id|
assert_equal({}, joined(id))
end
in_group_custom do |id|
assert_equal({}, joined(id))
end
end

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
3 changes: 0 additions & 3 deletions client/test/group_joined_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ def self.id58_prefix
in_kata do |id|
assert_equal({}, group_joined(id), :in_kata)
end
in_kata_custom do |id|
assert_equal({}, group_joined(id), :in_kata_custom)
end
end

private
Expand Down
3 changes: 0 additions & 3 deletions client/test/kata_exists_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ def self.id58_prefix
in_kata do |id|
assert kata_exists?(id), :in_kata
end
in_kata_custom do |id|
assert kata_exists?(id), :in_kata_custom
end
end

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
4 changes: 1 addition & 3 deletions client/test/kata_option_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ def self.id58_prefix
end

def id58_setup
ltf_name = any_languages_start_points_display_name
exercise_name = any_exercises_start_points_display_name
@id = kata_create(version, ltf_name, exercise_name)
@id = kata_create(custom_manifest)
end

attr_reader :id
Expand Down
22 changes: 22 additions & 0 deletions client/test/kata_test_data.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
module KataTestData

def manifest_Tennis_refactoring_Python_unitttest
{
"display_name" => "Tennis refactoring, Python unitttest",
"filename_extension" => [".py"],
"image_name" => "cyberdojofoundation/python_unittest:b8333d3",
"visible_files" => {
"cyber-dojo.sh" => {
"content" => "python -m unittest *test*.py\n"
},
"readme.txt" => {
"content" => "Tennis has a rather quirky scoring system, and to newcomers it \ncan be a little difficult to keep track of. The local tennis club\nhas some code that is currently being used to update the scoreboard\nwhen a player scores a point. They has recently acquired two smaller\ntennis clubs, and they two each have a similar piece of code.\n\nYou have just been employed by the tennis club, and your job \nis to refactor all three codebases until you are happy to\nwork with any of them. The future is uncertain, new features may\nbe needed, and you want to be thoroughly on top of your game when\nthat happens.\n\nSummary of Tennis scoring:\n1. A game is won by the first player to have won at least four points \n in total and at least two points more than the opponent.\n2. The running score of each game is described in a manner peculiar \n to tennis: scores from zero to three points are described as “love”, \n “fifteen”, “thirty”, and “forty” respectively.\n3. If at least three points have been scored by each player, and the \n scores are equal, the score is “deuce”.\n4. If at least three points have been scored by each side and a player\n has one more point than his opponent, the score of the game is\n “advantage” for the player in the lead."
},
"tennis.py" => {
"content" => "# -*- coding: utf-8 -*-\n\nclass TennisGame1:\n\n def __init__(self, player1Name, player2Name):\n self.player1Name = player1Name\n self.player2Name = player2Name\n self.p1points = 0\n self.p2points = 0\n \n def won_point(self, playerName):\n if playerName == self.player1Name:\n self.p1points += 1\n else:\n self.p2points += 1\n \n def score(self):\n result = \"\"\n tempScore=0\n if (self.p1points==self.p2points):\n result = {\n 0 : \"Love-All\",\n 1 : \"Fifteen-All\",\n 2 : \"Thirty-All\",\n }.get(self.p1points, \"Deuce\")\n elif (self.p1points>=4 or self.p2points>=4):\n minusResult = self.p1points-self.p2points\n if (minusResult==1):\n result =\"Advantage \" + self.player1Name\n elif (minusResult ==-1):\n result =\"Advantage \" + self.player2Name\n elif (minusResult>=2):\n result = \"Win for \" + self.player1Name\n else:\n result =\"Win for \" + self.player2Name\n else:\n for i in range(1,3):\n if (i==1):\n tempScore = self.p1points\n else:\n result+=\"-\"\n tempScore = self.p2points\n result += {\n 0 : \"Love\",\n 1 : \"Fifteen\",\n 2 : \"Thirty\",\n 3 : \"Forty\",\n }[tempScore]\n return result\n\n\nclass TennisGame2:\n def __init__(self, player1Name, player2Name):\n self.player1Name = player1Name\n self.player2Name = player2Name\n self.p1points = 0\n self.p2points = 0\n \n def won_point(self, playerName):\n if playerName == self.player1Name:\n self.P1Score()\n else:\n self.P2Score()\n \n def score(self):\n result = \"\"\n if (self.p1points == self.p2points and self.p1points < 3):\n if (self.p1points==0):\n result = \"Love\"\n if (self.p1points==1):\n result = \"Fifteen\"\n if (self.p1points==2):\n result = \"Thirty\"\n result += \"-All\"\n if (self.p1points==self.p2points and self.p1points>2):\n result = \"Deuce\"\n \n P1res = \"\"\n P2res = \"\"\n if (self.p1points > 0 and self.p2points==0):\n if (self.p1points==1):\n P1res = \"Fifteen\"\n if (self.p1points==2):\n P1res = \"Thirty\"\n if (self.p1points==3):\n P1res = \"Forty\"\n \n P2res = \"Love\"\n result = P1res + \"-\" + P2res\n if (self.p2points > 0 and self.p1points==0):\n if (self.p2points==1):\n P2res = \"Fifteen\"\n if (self.p2points==2):\n P2res = \"Thirty\"\n if (self.p2points==3):\n P2res = \"Forty\"\n \n P1res = \"Love\"\n result = P1res + \"-\" + P2res\n \n \n if (self.p1points>self.p2points and self.p1points < 4):\n if (self.p1points==2):\n P1res=\"Thirty\"\n if (self.p1points==3):\n P1res=\"Forty\"\n if (self.p2points==1):\n P2res=\"Fifteen\"\n if (self.p2points==2):\n P2res=\"Thirty\"\n result = P1res + \"-\" + P2res\n if (self.p2points>self.p1points and self.p2points < 4):\n if (self.p2points==2):\n P2res=\"Thirty\"\n if (self.p2points==3):\n P2res=\"Forty\"\n if (self.p1points==1):\n P1res=\"Fifteen\"\n if (self.p1points==2):\n P1res=\"Thirty\"\n result = P1res + \"-\" + P2res\n \n if (self.p1points > self.p2points and self.p2points >= 3):\n result = \"Advantage \" + self.player1Name\n \n if (self.p2points > self.p1points and self.p1points >= 3):\n result = \"Advantage \" + self.player2Name\n \n if (self.p1points>=4 and self.p2points>=0 and (self.p1points-self.p2points)>=2):\n result = \"Win for \" + self.player1Name\n if (self.p2points>=4 and self.p1points>=0 and (self.p2points-self.p1points)>=2):\n result = \"Win for \" + self.player2Name\n return result\n \n def SetP1Score(self, number):\n for i in range(number):\n self.P1Score()\n \n def SetP2Score(self, number):\n for i in range(number):\n self.P2Score()\n \n def P1Score(self):\n self.p1points +=1\n \n \n def P2Score(self):\n self.p2points +=1\n \nclass TennisGame3:\n def __init__(self, player1Name, player2Name):\n self.p1N = player1Name\n self.p2N = player2Name\n self.p1 = 0\n self.p2 = 0\n \n def won_point(self, n):\n if n == self.p1N:\n self.p1 += 1\n else:\n self.p2 += 1\n \n def score(self):\n if (self.p1 < 4 and self.p2 < 4) and (self.p1 + self.p2 < 6):\n p = [\"Love\", \"Fifteen\", \"Thirty\", \"Forty\"]\n s = p[self.p1]\n return s + \"-All\" if (self.p1 == self.p2) else s + \"-\" + p[self.p2]\n else:\n if (self.p1 == self.p2):\n return \"Deuce\"\n s = self.p1N if self.p1 > self.p2 else self.p2N\n return \"Advantage \" + s if ((self.p1-self.p2)*(self.p1-self.p2) == 1) else \"Win for \" + s\n"
},
"tennis_unit_test.py" => {
"content" => "# -*- coding: utf-8 -*-\n\nimport unittest\n\nfrom tennis import TennisGame1, TennisGame2, TennisGame3\n\ntest_cases = [\n (0, 0, \"Love-All\", 'player1', 'player2'),\n (1, 1, \"Fifteen-All\", 'player1', 'player2'),\n (2, 2, \"Thirty-All\", 'player1', 'player2'),\n (3, 3, \"Deuce\", 'player1', 'player2'),\n (4, 4, \"Deuce\", 'player1', 'player2'),\n\n (1, 0, \"Fifteen-Love\", 'player1', 'player2'),\n (0, 1, \"Love-Fifteen\", 'player1', 'player2'),\n (2, 0, \"Thirty-Love\", 'player1', 'player2'),\n (0, 2, \"Love-Thirty\", 'player1', 'player2'),\n (3, 0, \"Forty-Love\", 'player1', 'player2'),\n (0, 3, \"Love-Forty\", 'player1', 'player2'),\n (4, 0, \"Win for player1\", 'player1', 'player2'),\n (0, 4, \"Win for player2\", 'player1', 'player2'),\n\n (2, 1, \"Thirty-Fifteen\", 'player1', 'player2'),\n (1, 2, \"Fifteen-Thirty\", 'player1', 'player2'),\n (3, 1, \"Forty-Fifteen\", 'player1', 'player2'),\n (1, 3, \"Fifteen-Forty\", 'player1', 'player2'),\n (4, 1, \"Win for player1\", 'player1', 'player2'),\n (1, 4, \"Win for player2\", 'player1', 'player2'),\n\n (3, 2, \"Forty-Thirty\", 'player1', 'player2'),\n (2, 3, \"Thirty-Forty\", 'player1', 'player2'),\n (4, 2, \"Win for player1\", 'player1', 'player2'),\n (2, 4, \"Win for player2\", 'player1', 'player2'),\n\n (4, 3, \"Advantage player1\", 'player1', 'player2'),\n (3, 4, \"Advantage player2\", 'player1', 'player2'),\n (5, 4, \"Advantage player1\", 'player1', 'player2'),\n (4, 5, \"Advantage player2\", 'player1', 'player2'),\n (15, 14, \"Advantage player1\", 'player1', 'player2'),\n (14, 15, \"Advantage player2\", 'player1', 'player2'),\n\n (6, 4, 'Win for player1', 'player1', 'player2'), \n (4, 6, 'Win for player2', 'player1', 'player2'), \n (16, 14, 'Win for player1', 'player1', 'player2'), \n (14, 16, 'Win for player2', 'player1', 'player2'), \n\n (6, 4, 'Win for One', 'One', 'player2'),\n (4, 6, 'Win for Two', 'player1', 'Two'), \n (6, 5, 'Advantage One', 'One', 'player2'),\n (5, 6, 'Advantage Two', 'player1', 'Two'), \n \n ]\n\ndef play_game(TennisGame, p1Points, p2Points, p1Name, p2Name):\n game = TennisGame(p1Name, p2Name)\n for i in range(max(p1Points, p2Points)):\n if i < p1Points:\n game.won_point(p1Name)\n if i < p2Points:\n game.won_point(p2Name)\n return game\n\nclass TestTennis(unittest.TestCase):\n \n def test_Score_Game1(self):\n for testcase in test_cases:\n (p1Points, p2Points, score, p1Name, p2Name) = testcase\n game = play_game(TennisGame1, p1Points, p2Points, p1Name, p2Name)\n self.assertEqual(score, game.score())\n\n def test_Score_Game2(self):\n for testcase in test_cases:\n (p1Points, p2Points, score, p1Name, p2Name) = testcase\n game = play_game(TennisGame2, p1Points, p2Points, p1Name, p2Name)\n self.assertEqual(score, game.score())\n\n def test_Score_Game3(self):\n for testcase in test_cases:\n (p1Points, p2Points, score, p1Name, p2Name) = testcase\n game = play_game(TennisGame3, p1Points, p2Points, p1Name, p2Name)\n self.assertEqual(score, game.score())\n \nif __name__ == \"__main__\":\n unittest.main() \n "
}
}
}.clone
end

V0_KATA_ID = 'k5ZTk0'
V1_KATA_ID = 'rUqcey'

Expand Down

0 comments on commit 265f085

Please sign in to comment.