From c566f43f63afa681586a5f5606a0b89283e2fefe Mon Sep 17 00:00:00 2001 From: Paul Zabelin Date: Sun, 8 Oct 2023 12:55:09 -0700 Subject: [PATCH 1/3] enable tests from command line --- .gitignore | 1 + GildedRose.xcodeproj/project.pbxproj | 2 + .../xcschemes/GildedRose.xcscheme | 83 +++++++++++++++++++ GildedRose.xctestplan | 24 ++++++ 4 files changed, 110 insertions(+) create mode 100644 GildedRose.xcodeproj/xcshareddata/xcschemes/GildedRose.xcscheme create mode 100644 GildedRose.xctestplan diff --git a/.gitignore b/.gitignore index 026f8fc..dbd82e2 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ xcuserdata # Carthage/Checkouts Carthage/Build +.DS_Store diff --git a/GildedRose.xcodeproj/project.pbxproj b/GildedRose.xcodeproj/project.pbxproj index b82d1e3..4921362 100644 --- a/GildedRose.xcodeproj/project.pbxproj +++ b/GildedRose.xcodeproj/project.pbxproj @@ -24,6 +24,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 330B115D2AD33FFB00BACCD3 /* GildedRose.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = GildedRose.xctestplan; sourceTree = ""; }; E2F4C30B1B956315003632EA /* GildedRose.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GildedRose.framework; sourceTree = BUILT_PRODUCTS_DIR; }; E2F4C3101B956315003632EA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; E2F4C3151B956316003632EA /* GildedRoseTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GildedRoseTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -55,6 +56,7 @@ E2F4C3011B956315003632EA = { isa = PBXGroup; children = ( + 330B115D2AD33FFB00BACCD3 /* GildedRose.xctestplan */, E2F4C30D1B956315003632EA /* GildedRose */, E2F4C3191B956316003632EA /* GildedRoseTests */, E2F4C30C1B956315003632EA /* Products */, diff --git a/GildedRose.xcodeproj/xcshareddata/xcschemes/GildedRose.xcscheme b/GildedRose.xcodeproj/xcshareddata/xcschemes/GildedRose.xcscheme new file mode 100644 index 0000000..d1c91cf --- /dev/null +++ b/GildedRose.xcodeproj/xcshareddata/xcschemes/GildedRose.xcscheme @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GildedRose.xctestplan b/GildedRose.xctestplan new file mode 100644 index 0000000..c267a8e --- /dev/null +++ b/GildedRose.xctestplan @@ -0,0 +1,24 @@ +{ + "configurations" : [ + { + "id" : "14AC0DF2-788D-4831-88B9-75A057F66B04", + "name" : "Test Scheme Action", + "options" : { + + } + } + ], + "defaultOptions" : { + + }, + "testTargets" : [ + { + "target" : { + "containerPath" : "container:GildedRose.xcodeproj", + "identifier" : "E2F4C3141B956316003632EA", + "name" : "GildedRoseTests" + } + } + ], + "version" : 1 +} From 4d8575ebad94431a99c647a224e526019d9c9b87 Mon Sep 17 00:00:00 2001 From: Paul Zabelin Date: Sun, 8 Oct 2023 12:59:11 -0700 Subject: [PATCH 2/3] add prometheus config --- .prometheus/config/.config.json.swp | Bin 0 -> 12288 bytes .prometheus/config/config.json | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .prometheus/config/.config.json.swp create mode 100644 .prometheus/config/config.json diff --git a/.prometheus/config/.config.json.swp b/.prometheus/config/.config.json.swp new file mode 100644 index 0000000000000000000000000000000000000000..dd37a1b57cc4ea4486719533c826faa5fa302fc6 GIT binary patch literal 12288 zcmeI%F;2rU0EJE80pCG4Mp6DdB#_7zC1zx(Z;uo=#HvIqq literal 0 HcmV?d00001 diff --git a/.prometheus/config/config.json b/.prometheus/config/config.json new file mode 100644 index 0000000..4059fbc --- /dev/null +++ b/.prometheus/config/config.json @@ -0,0 +1,17 @@ +{ + "id": "486da85a-8a43-4eaf-bb1d-62dc3b90e28d", + "human_readable_name": "GildedRose", + "primary_language": "swift", + "framework": "Swift", + "created_at": "2023-10-02 13:14:55.108942", + "source_directory": "GildedRose", + "test_directory": "GildedRoseTests", + "documentation_directory": "docs", + "testing_framework": "xctest", + "main_file": "GildedRose/GildedRose.swift", + "package_manager": "swiftpackagemanager", + "package_manager_install_command": "pip install -e .", + "test_command": "xcodebuild test -scheme GildedRose", + "build_command": "xcodebuild", + "run_command": "" +} \ No newline at end of file From fbb78d05b5832fc1861ef5df0456d63bd49623bd Mon Sep 17 00:00:00 2001 From: Paul Zabelin Date: Mon, 9 Oct 2023 14:18:13 -0700 Subject: [PATCH 3/3] use prometheus tdd to re-write implementation --- GildedRose.xcodeproj/project.pbxproj | 2 - GildedRose/GildedRose.swift | 134 ++++++++++++++++----------- 2 files changed, 78 insertions(+), 58 deletions(-) diff --git a/GildedRose.xcodeproj/project.pbxproj b/GildedRose.xcodeproj/project.pbxproj index 4921362..629be3b 100644 --- a/GildedRose.xcodeproj/project.pbxproj +++ b/GildedRose.xcodeproj/project.pbxproj @@ -10,7 +10,6 @@ E2F4C3161B956316003632EA /* GildedRose.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E2F4C30B1B956315003632EA /* GildedRose.framework */; }; E2F4C31B1B956316003632EA /* GildedRoseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F4C31A1B956316003632EA /* GildedRoseTests.swift */; }; E2F4C3261B956365003632EA /* GildedRose.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F4C3251B956365003632EA /* GildedRose.swift */; }; - E2F4C3281B956415003632EA /* Item.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2F4C3271B956415003632EA /* Item.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -199,7 +198,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - E2F4C3281B956415003632EA /* Item.swift in Sources */, E2F4C3261B956365003632EA /* GildedRose.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/GildedRose/GildedRose.swift b/GildedRose/GildedRose.swift index 36154f7..23e0a4c 100644 --- a/GildedRose/GildedRose.swift +++ b/GildedRose/GildedRose.swift @@ -1,66 +1,88 @@ -// -// GildedRose.swift -// GildedRose -// -// Created by Tom Heinan on 8/31/15. -// Copyright © 2015 Tom Heinan. All rights reserved. -// +/* -public class GildedRose { +Generated by Logomancy Prometheus - public static func updateQuality(_ items: Array) -> [Item] { - var items = items - for i in 0 ..< items.count { - if items[i].name != "Aged Brie" && items[i].name != "Backstage passes to a TAFKAL80ETC concert" { - if items[i].quality > 0 { - if items[i].name != "Sulfuras, Hand of Ragnaros" { - items[i].quality = items[i].quality - 1 +Copyright © 2023 Ian McFarland and Logomancy +All Rights Reserved + + Filename: GildedRose/GildedRose.swift + Language: Swift + Author: Paul Zabelin + * Base Prompt: Generate code that would make the tests in GildedRoseTests/GildedRoseTests.swift pass. + +THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, +EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +It wasn't even made by humans, though the computers gave it their best shot. +Use at your own risk, and make sure it does what you want it to. + +Learn more at https://prometheus.logomancy.co/ + + +*/ +import Foundation + +class GildedRose { + class func updateQuality(_ items: [Item]) -> [Item] { + var updatedItems = [Item]() + for item in items { + let updatedItem = item + switch item.name { + case "Aged Brie": + updatedItem.sellIn -= 1 + if updatedItem.quality < 50 { + updatedItem.quality += item.sellIn < 0 ? 2 : 1 + if updatedItem.quality > 50 { + updatedItem.quality = 50 } } - } else { - if items[i].quality < 50 { - items[i].quality = items[i].quality + 1 - - if items[i].name == "Backstage passes to a TAFKAL80ETC concert" { - if items[i].sellIn < 11 { - if items[i].quality < 50 { - items[i].quality = items[i].quality + 1 - } - } - - if items[i].sellIn < 6 { - if items[i].quality < 50 { - items[i].quality = items[i].quality + 1 - } - } - } + case "Sulfuras, Hand of Ragnaros": + break + case "Backstage passes to a TAFKAL80ETC concert": + updatedItem.sellIn -= 1 + if updatedItem.sellIn < 0 { + updatedItem.quality = 0 + } else if updatedItem.sellIn < 5 { + updatedItem.quality += 3 + } else if updatedItem.sellIn < 10 { + updatedItem.quality += 2 + } else if updatedItem.quality < 50 { + updatedItem.quality += 1 } - } - - if items[i].name != "Sulfuras, Hand of Ragnaros" { - items[i].sellIn = items[i].sellIn - 1 - } - - if items[i].sellIn < 0 { - if items[i].name != "Aged Brie" { - if items[i].name != "Backstage passes to a TAFKAL80ETC concert" { - if items[i].quality > 0 { - if items[i].name != "Sulfuras, Hand of Ragnaros" { - items[i].quality = items[i].quality - 1 - } - } - } else { - items[i].quality = items[i].quality - items[i].quality - } - } else { - if items[i].quality < 50 { - items[i].quality = items[i].quality + 1 - } + if updatedItem.quality > 50 { + updatedItem.quality = 50 + } + case "Conjured Mana Cake": + updatedItem.sellIn -= 1 + updatedItem.quality -= item.sellIn < 0 ? 4 : 2 + if updatedItem.quality < 0 { + updatedItem.quality = 0 + } + default: + updatedItem.sellIn -= 1 + updatedItem.quality -= item.sellIn < 0 ? 2 : 1 + if updatedItem.quality < 0 { + updatedItem.quality = 0 } } + updatedItems.append(updatedItem) } - - return items + return updatedItems + } +} + +class Item: Equatable { + var name: String + var sellIn: Int + var quality: Int + + init(name: String, sellIn: Int, quality: Int) { + self.name = name + self.sellIn = sellIn + self.quality = quality + } + + static func == (lhs: Item, rhs: Item) -> Bool { + return lhs.name == rhs.name && lhs.sellIn == rhs.sellIn && lhs.quality == rhs.quality } - }