mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
Merge branch 'emilybache:main' into master
This commit is contained in:
commit
048d719f75
30
GildedRoseRequirements_ar.md
Normal file
30
GildedRoseRequirements_ar.md
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# مواصفات متطلبات Gilded Rose
|
||||||
|
|
||||||
|
مرحبًا بكم في فريق Gilded Rose. كما تعلمون، نحن نُدير نزلاً صغيرًا بموقع مميز في مدينة بارزة يديره صاحب نزل ودود يُدعى Allison. نحن نشتري ونبيع فقط أرقى البضائع.
|
||||||
|
لسوء الحظ، بضائعنا تتدهور في (Quality) القيمة مع اقتراب تاريخ بيعها.
|
||||||
|
|
||||||
|
لدينا نظام يقوم بتحديث المخزون لدينا. تم تطويره بواسطة شخص عملي يُدعى Leeroy، الذي انتقل الآن إلى مغامرات جديدة.
|
||||||
|
مهمتك هي إضافة ميزة جديدة إلى نظامنا لكي نبدأ ببيع فئة جديدة من العناصر. أولاً، مقدمة عن نظامنا:
|
||||||
|
|
||||||
|
- جميع (Items) العناصر لها قيمة (SellIn) تاريخ البيع، والذي يشير إلى عدد الأيام المتبقية لبيع (Items) العناصر.
|
||||||
|
- جميع (Items) العناصر لها (Quality) القيمة، والتي تدل على مدى قيمة العنصر.
|
||||||
|
- في نهاية كل يوم، يقوم نظامنا بتقليل القيمتين لكل عنصر.
|
||||||
|
|
||||||
|
بسيط، أليس كذلك؟ حسنًا، هنا تصبح الأمور مثيرة:
|
||||||
|
|
||||||
|
- بمجرد أن يمر تاريخ البيع، تتدهور (Quality) القيمة بمعدل مضاعف.
|
||||||
|
- لا يمكن أن تكون قيمة (Quality) سالبة أبدًا.
|
||||||
|
- __"Aged Brie"__ تزداد (Quality) القيمة الخاصة به مع تقدم عمره.
|
||||||
|
- لا يمكن أن تتجاوز (Quality) القيمة أكثر من `50`.
|
||||||
|
- __"Sulfuras"__، كونه عنصرًا أسطوريًا، لا يحتاج أبدًا إلى البيع ولا تتناقص (Quality) القيمة الخاصة به.
|
||||||
|
- __"Backstage passes"__، مثل Aged Brie، تزداد (Quality) القيمة الخاصة به مع اقتراب موعد البيع:
|
||||||
|
- تزداد (Quality) القيمة بمقدار `2` عندما يتبقى `10` أيام أو أقل، وبمقدار `3` عندما يتبقى `5` أيام أو أقل.
|
||||||
|
- ولكن، تنخفض (Quality) القيمة إلى `0` بعد انتهاء الحفل.
|
||||||
|
|
||||||
|
لقد وقعنا مؤخرًا عقدًا مع مورد لعناصر __"Conjured"__. هذا يتطلب تحديثًا لنظامنا:
|
||||||
|
|
||||||
|
- عناصر __"Conjured"__ تتدهور (Quality) القيمة الخاصة بها بمعدل أسرع مرتين من العناصر العادية.
|
||||||
|
|
||||||
|
يمكنك إجراء أي تغييرات على دالة `UpdateQuality` وإضافة أي كود جديد طالما أن كل شيء لا يزال يعمل بشكل صحيح. ومع ذلك، لا تقم بتعديل فئة `Item` أو خاصية (Items) العناصر، لأن الغول الجالس في الزاوية سيغضب بشدة وقد يقضي عليك في لحظة، فهو لا يؤمن بمشاركة ملكية الكود (يمكنك جعل `UpdateQuality` و (Items) العناصر ساكنين static إذا أردت، وسنتكفل نحن بالتغطية عليك).
|
||||||
|
|
||||||
|
للتوضيح فقط، لا يمكن لـ (Quality) القيمة لأي عنصر أن تزيد عن `50`، باستثناء __"Sulfuras"__، حيث أن (Quality) القيمة الخاصة به تساوي `80` ولا تتغير أبدًا.
|
||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@ -14,9 +14,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
<PackageReference Include="xunit" Version="2.9.3" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
@ -27,7 +27,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Update="FSharp.Core" Version="6.0.1" />
|
<PackageReference Update="FSharp.Core" Version="9.0.202" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@ -11,10 +11,10 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
||||||
<PackageReference Include="Unquote" Version="6.1.0" />
|
<PackageReference Include="Unquote" Version="7.0.1" />
|
||||||
<PackageReference Include="xunit" Version="2.4.1" />
|
<PackageReference Include="xunit" Version="2.9.3" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
|
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.0">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
@ -25,7 +25,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Update="FSharp.Core" Version="6.0.1" />
|
<PackageReference Update="FSharp.Core" Version="9.0.202" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -10,7 +10,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Update="FSharp.Core" Version="6.0.1" />
|
<PackageReference Update="FSharp.Core" Version="9.0.202" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
3
odin/.gitignore
vendored
Normal file
3
odin/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
*.o
|
||||||
|
*.bin
|
||||||
|
*.exe
|
||||||
34
odin/README.md
Normal file
34
odin/README.md
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Gilded Rose starting position in Odin
|
||||||
|
|
||||||
|
Learn how to install Odin on your system [here](https://odin-lang.org/docs/install/)
|
||||||
|
|
||||||
|
## Run unit tests from the command line
|
||||||
|
```
|
||||||
|
$ odin test tests
|
||||||
|
```
|
||||||
|
## Run the TextTest fixture on the command line
|
||||||
|
Build the executable:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ odin build src -out:gilded_rose<include your OS executable extension here i.e. .bin>
|
||||||
|
```
|
||||||
|
|
||||||
|
Execute it on the command line with an argument for the number of days:
|
||||||
|
|
||||||
|
### macOS:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ ./gilded_rose.bin 10
|
||||||
|
```
|
||||||
|
### Windows:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ ./gilded_rose.exe 10
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run the TextTest approval test that comes with this project
|
||||||
|
There are instructions in the TextTest Readme for setting up TextTest. You will need to specify the executable in `config.gr`. Uncomment this line to use it:
|
||||||
|
|
||||||
|
```
|
||||||
|
#executable:${TEXTTEST_HOME}/odin/gilded_rose<include your OS executable extension here>
|
||||||
|
```
|
||||||
55
odin/src/core/gilded_rose.odin
Normal file
55
odin/src/core/gilded_rose.odin
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
package gilded_rose
|
||||||
|
|
||||||
|
Item :: struct {
|
||||||
|
name: string,
|
||||||
|
sell_in: i32,
|
||||||
|
quality: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
update_quality :: proc(inventory: []Item) {
|
||||||
|
for &item in inventory {
|
||||||
|
if item.name != "Aged Brie" && item.name != "Backstage passes to a TAFKAL80ETC concert" {
|
||||||
|
if item.quality > 0 {
|
||||||
|
if item.name != "Sulfuras, Hand of Ragnaros" {
|
||||||
|
item.quality = item.quality - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if item.quality < 50 {
|
||||||
|
item.quality = item.quality + 1
|
||||||
|
if item.name == "Backstage passes to a TAFKAL80ETC concert" {
|
||||||
|
if item.sell_in < 11 {
|
||||||
|
if item.quality < 50 {
|
||||||
|
item.quality = item.quality + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if item.sell_in < 6 {
|
||||||
|
if item.quality < 50 {
|
||||||
|
item.quality = item.quality + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if item.name != "Sulfuras, Hand of Ragnaros" {
|
||||||
|
item.sell_in = item.sell_in - 1
|
||||||
|
}
|
||||||
|
if item.sell_in < 0 {
|
||||||
|
if item.name != "Aged Brie" {
|
||||||
|
if item.name != "Backstage passes to a TAFKAL80ETC concert" {
|
||||||
|
if item.quality > 0 {
|
||||||
|
if item.name != "Sulfuras, Hand of Ragnaros" {
|
||||||
|
item.quality = item.quality - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
item.quality = item.quality - item.quality
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if item.quality < 50 {
|
||||||
|
item.quality = item.quality + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
46
odin/src/main.odin
Normal file
46
odin/src/main.odin
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import GildedRose "./core"
|
||||||
|
import "core:fmt"
|
||||||
|
import "core:os"
|
||||||
|
import "core:slice"
|
||||||
|
import "core:strconv"
|
||||||
|
|
||||||
|
main :: proc() {
|
||||||
|
days := 2
|
||||||
|
if num_of_days, arg_ok := slice.get(os.args, 1); arg_ok {
|
||||||
|
if val, ok := strconv.parse_int(num_of_days); ok && val > 0 {
|
||||||
|
days = val
|
||||||
|
} else {
|
||||||
|
fmt.eprintf("Please enter a number greater than 0\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
items := []GildedRose.Item {
|
||||||
|
{"+5 Dexterity Vest", 10, 20},
|
||||||
|
{"Aged Brie", 2, 0},
|
||||||
|
{"Elixir of the Mongoose", 5, 7},
|
||||||
|
{"Sulfuras, Hand of Ragnaros", 0, 80},
|
||||||
|
{"Sulfuras, Hand of Ragnaros", -1, 80},
|
||||||
|
{"Backstage passes to a TAFKAL80ETC concert", 15, 20},
|
||||||
|
{"Backstage passes to a TAFKAL80ETC concert", 10, 49},
|
||||||
|
{"Backstage passes to a TAFKAL80ETC concert", 5, 49},
|
||||||
|
// This Conjured item does not work properly yet
|
||||||
|
{"Conjured Mana Cake", 3, 6},
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.println("OMGHAI!")
|
||||||
|
|
||||||
|
for day in 0 ..= days {
|
||||||
|
day_line := fmt.tprint("-------- day", day, "--------")
|
||||||
|
fmt.println(day_line)
|
||||||
|
fmt.println("name, sellIn, quality")
|
||||||
|
for item in items {
|
||||||
|
item_line := fmt.tprint(item.name, item.sell_in, item.quality, sep = ", ")
|
||||||
|
fmt.println(item_line)
|
||||||
|
}
|
||||||
|
fmt.println()
|
||||||
|
GildedRose.update_quality(items)
|
||||||
|
}
|
||||||
|
}
|
||||||
11
odin/tests/gilded_rose_test.odin
Normal file
11
odin/tests/gilded_rose_test.odin
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package test_gilded_rose
|
||||||
|
|
||||||
|
import GildedRose "../src/core"
|
||||||
|
import "core:testing"
|
||||||
|
|
||||||
|
@(test)
|
||||||
|
update_quality_test :: proc(t: ^testing.T) {
|
||||||
|
items := []GildedRose.Item{{"food", 0, 0}}
|
||||||
|
GildedRose.update_quality(items)
|
||||||
|
testing.expect(t, "fixme" == items[0].name, "Fix this test")
|
||||||
|
}
|
||||||
@ -64,4 +64,7 @@ interpreter:ruby
|
|||||||
# Settings for the OCaml version
|
# Settings for the OCaml version
|
||||||
# executable:${TEXTTEST_HOME}/ocaml/_build/default/bin/main.exe
|
# executable:${TEXTTEST_HOME}/ocaml/_build/default/bin/main.exe
|
||||||
|
|
||||||
|
# Settings for the Odin version
|
||||||
|
#executable:${TEXTTEST_HOME}/odin/gilded_rose<include your OS executable extension here>
|
||||||
|
|
||||||
filename_convention_scheme:standard
|
filename_convention_scheme:standard
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user