Skip to content

Commit

Permalink
Add group/kata create2(manifest) methods as a step in switching back …
Browse files Browse the repository at this point in the history
…to create methods that accept a manifest
  • Loading branch information
JonJagger committed Aug 21, 2021
1 parent 0acf8b5 commit 80b83a8
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/source/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def initialize(externals)

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

post_json(:model, :group_create2)
post_json(:model, :group_create_custom)
post_json(:model, :group_create)
get_json(:model, :group_exists?)
Expand All @@ -22,6 +23,7 @@ def initialize(externals)

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

post_json(:model, :kata_create2)
post_json(:model, :kata_create_custom)
post_json(:model, :kata_create)
get_json(:model, :kata_download)
Expand Down
16 changes: 16 additions & 0 deletions app/source/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ def initialize(externals)

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

def group_create2(manifest:)
version = from_manifest(manifest)
group(version).create(manifest)
end

def group_create_custom(version:, display_name:)
manifest = build_custom_manifest(version, display_name)
group(version).create(manifest)
Expand Down Expand Up @@ -60,6 +65,11 @@ def group_fork(id:, index:)

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

def kata_create2(manifest:)
version = from_manifest(manifest)
kata(version).create(manifest)
end

def kata_create_custom(version:, display_name:)
manifest = build_custom_manifest(version, display_name)
kata(version).create(manifest)
Expand Down Expand Up @@ -164,6 +174,12 @@ def from_path(path)
manifest['version'].to_i # nil.to_i == 0
end

def from_manifest(manifest)
# All newly created groups and katas use the current version.
# Allow creation from previous versions for tests.
(manifest['version'] || CURRENT_VERSION).to_i
end

def id?(id)
IdGenerator::id?(id)
end
Expand Down
6 changes: 3 additions & 3 deletions app/test/config/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
warnings:0,
skips:0,

duration:16,
duration:60,

test: {
lines: {
total:1838,
total:1864,
missed:0,
},
branches: {
Expand All @@ -24,7 +24,7 @@

code: {
lines: {
total:1371,
total:1379,
missed:0,
},
branches: {
Expand Down
22 changes: 22 additions & 0 deletions app/test/data/kata_test_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,28 @@ def kata_event_k5ZTk0_3
}
end

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

=begin
def print_cmp(expected, actual)
actual.each do |key,value|
Expand Down
28 changes: 28 additions & 0 deletions app/test/group_create2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require_relative 'test_base'

class GroupCreate2Test < TestBase

def self.id58_prefix
'e08'
end

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

versions3_test 'h35', %w(
|POST /group_create(manifest)
|has status 200
|returns the id: of a new group
|that exists in saver
) do
assert_json_post_200(
path = 'group_create2',
{ manifest:custom_manifest2 }.to_json
) do |response|
assert_equal [path], response.keys, :keys
id = response[path]
assert group_exists?(id), :exists
assert_equal version, group_manifest(id)['version'], :version
end
end

end
8 changes: 8 additions & 0 deletions app/test/helpers/model.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module TestHelpersModel

#def group_create2(manifest)
# model.group_create2(manifest:manifest)
#end

def group_create_custom(version, display_name)
model.group_create_custom(version:version, display_name:display_name)
end
Expand Down Expand Up @@ -36,6 +40,10 @@ def group_fork(id, index)

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

#def kata_create2(manifest)
# model.kata_create2(manifest:manifest)
#end

def kata_create_custom(version, display_name)
model.kata_create_custom(version:version, display_name:display_name)
end
Expand Down
28 changes: 28 additions & 0 deletions app/test/kata_create2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require_relative 'test_base'

class KataCreate2Test < TestBase

def self.id58_prefix
'e09'
end

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

versions3_test 'h35', %w(
|POST /kata_create(manifest)
|has status 200
|returns the id: of a new kata
|that exists in saver
) do
assert_json_post_200(
path = 'kata_create2',
{ manifest:custom_manifest2 }.to_json
) do |response|
assert_equal [path], response.keys, :keys
id = response[path]
assert kata_exists?(id), :exists
assert_equal version, kata_manifest(id)['version'], :version
end
end

end
8 changes: 8 additions & 0 deletions app/test/test_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def custom_manifest

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

def custom_manifest2
manifest = manifest_Tennis_refactoring_Python_unitttest
manifest['version'] = version
manifest
end

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

def self.disk_tests(id58_suffix, *lines, &block)
test(id58_suffix, ["<disk:Real>"]+lines) do
self.instance_exec(&block)
Expand Down
2 changes: 1 addition & 1 deletion client/test/config/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
warnings:0,
skips:0,

duration:10,
duration:30,

code: {
lines: {
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ services:
- exercises-start-points

custom-start-points:
image: cyberdojo/custom-start-points:513f842
image: cyberdojo/custom-start-points:970bd78
container_name: test_saver_custom_start_points
user: nobody
env_file: [ .env ]
Expand All @@ -60,7 +60,7 @@ services:
tmpfs: /tmp

languages-start-points:
image: cyberdojo/languages-start-points:f7e6555
image: cyberdojo/languages-start-points:119899a
container_name: test_saver_languages_start_points
user: nobody
env_file: [ .env ]
Expand All @@ -69,7 +69,7 @@ services:
tmpfs: /tmp

exercises-start-points:
image: cyberdojo/exercises-start-points:0d14dad
image: cyberdojo/exercises-start-points:af27502
container_name: test_saver_exercises_start_points
user: nobody
env_file: [ .env ]
Expand Down
4 changes: 2 additions & 2 deletions wait.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ echo_docker_log()
containers_wait()
{
exit_non_zero_unless_healthy $(server_container) $(server_name)
exit_non_zero_unless_clean $(server_container)
#exit_non_zero_unless_clean $(server_container)

exit_non_zero_unless_healthy $(client_container) $(client_name)
exit_non_zero_unless_clean $(client_container)
#exit_non_zero_unless_clean $(client_container)
}

# - - - - - - - - - - - - - - - - - - - -
Expand Down

0 comments on commit 80b83a8

Please sign in to comment.