mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
cargo fmt
Standard Rust formatting practice
This commit is contained in:
parent
fbe24e35b5
commit
a699803ce7
@ -4,17 +4,21 @@ use std::vec;
|
|||||||
pub struct Item {
|
pub struct Item {
|
||||||
pub name: string::String,
|
pub name: string::String,
|
||||||
pub sell_in: i32,
|
pub sell_in: i32,
|
||||||
pub quality: i32
|
pub quality: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Item {
|
impl Item {
|
||||||
pub fn new(name: String, sell_in: i32, quality: i32) -> Item {
|
pub fn new(name: String, sell_in: i32, quality: i32) -> Item {
|
||||||
Item {name: name, sell_in: sell_in, quality: quality}
|
Item {
|
||||||
|
name: name,
|
||||||
|
sell_in: sell_in,
|
||||||
|
quality: quality,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GildedRose {
|
pub struct GildedRose {
|
||||||
pub items: vec::Vec<Item>
|
pub items: vec::Vec<Item>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GildedRose {
|
impl GildedRose {
|
||||||
@ -24,15 +28,15 @@ impl GildedRose {
|
|||||||
|
|
||||||
pub fn update_quality(&mut self) {
|
pub fn update_quality(&mut self) {
|
||||||
for item in &mut self.items {
|
for item in &mut self.items {
|
||||||
if item.name != "Aged Brie" && item.name != "Backstage passes to a TAFKAL80ETC concert" {
|
if item.name != "Aged Brie" && item.name != "Backstage passes to a TAFKAL80ETC concert"
|
||||||
|
{
|
||||||
if item.quality > 0 {
|
if item.quality > 0 {
|
||||||
if item.name != "Sulfuras, Hand of Ragnaros" {
|
if item.name != "Sulfuras, Hand of Ragnaros" {
|
||||||
item.quality = item.quality - 1;
|
item.quality = item.quality - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if item.quality < 50
|
if item.quality < 50 {
|
||||||
{
|
|
||||||
item.quality = item.quality + 1;
|
item.quality = item.quality + 1;
|
||||||
|
|
||||||
if item.name == "Backstage passes to a TAFKAL80ETC concert" {
|
if item.name == "Backstage passes to a TAFKAL80ETC concert" {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use super::{Item, GildedRose};
|
use super::{GildedRose, Item};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn foo() {
|
pub fn foo() {
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
|
|
||||||
mod gildedrose;
|
mod gildedrose;
|
||||||
|
|
||||||
use gildedrose::{Item, GildedRose};
|
use gildedrose::{GildedRose, Item};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let items = vec![
|
let items = vec![
|
||||||
@ -10,11 +9,23 @@ fn main() {
|
|||||||
Item::new(String::from("Elixir of the Mongoose"), 5, 7),
|
Item::new(String::from("Elixir of the Mongoose"), 5, 7),
|
||||||
Item::new(String::from("Sulfuras, Hand of Ragnaros"), 0, 80),
|
Item::new(String::from("Sulfuras, Hand of Ragnaros"), 0, 80),
|
||||||
Item::new(String::from("Sulfuras, Hand of Ragnaros"), -1, 80),
|
Item::new(String::from("Sulfuras, Hand of Ragnaros"), -1, 80),
|
||||||
Item::new(String::from("Backstage passes to a TAFKAL80ETC concert"), 15, 20),
|
Item::new(
|
||||||
Item::new(String::from("Backstage passes to a TAFKAL80ETC concert"), 10, 49),
|
String::from("Backstage passes to a TAFKAL80ETC concert"),
|
||||||
Item::new(String::from("Backstage passes to a TAFKAL80ETC concert"), 5, 49),
|
15,
|
||||||
|
20,
|
||||||
|
),
|
||||||
|
Item::new(
|
||||||
|
String::from("Backstage passes to a TAFKAL80ETC concert"),
|
||||||
|
10,
|
||||||
|
49,
|
||||||
|
),
|
||||||
|
Item::new(
|
||||||
|
String::from("Backstage passes to a TAFKAL80ETC concert"),
|
||||||
|
5,
|
||||||
|
49,
|
||||||
|
),
|
||||||
// this conjured item does not work properly yet
|
// this conjured item does not work properly yet
|
||||||
Item::new(String::from("Conjured Mana Cake"), 3, 6)
|
Item::new(String::from("Conjured Mana Cake"), 3, 6),
|
||||||
];
|
];
|
||||||
let mut rose = GildedRose::new(items);
|
let mut rose = GildedRose::new(items);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user