Skip to content

Commit

Permalink
Add mutability concept to roman-numerals + update difficulty to 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Nenad committed Jul 2, 2024
1 parent 9e7bbc0 commit 671691b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 34 deletions.
7 changes: 7 additions & 0 deletions concepts/mutability/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"blurb": "<todo>",
"authors": [
"misicnenad"
],
"contributors": []
}
1 change: 1 addition & 0 deletions concepts/mutability/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Mutability
1 change: 1 addition & 0 deletions concepts/mutability/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Introduction
1 change: 1 addition & 0 deletions concepts/mutability/links.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
11 changes: 8 additions & 3 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@
"name": "Roman Numerals",
"uuid": "3fb4bd2f-bc5f-4a67-b9cc-49a786245876",
"practices": [
"tuples",
"traits",
"type-conversion"
"type-conversion",
"mutability"
],
"prerequisites": [],
"difficulty": 2
"difficulty": 3
},
{
"slug": "binary-search",
Expand Down Expand Up @@ -286,6 +286,11 @@
"uuid": "fe81e75b-b4d2-4ee8-9aaa-271e76468d0b",
"slug": "printing",
"name": "Printing"
},
{
"uuid": "8a4a6525-c1e4-44f5-ab6b-cf5d8ce6701e",
"slug": "mutability",
"name": "M`utability"
}
],
"key_features": [
Expand Down
9 changes: 5 additions & 4 deletions exercises/practice/roman-numerals/.meta/example.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::fmt::{Display, Error, Formatter};

#[derive(Drop)]
pub struct Roman {
value: ByteArray,
Expand Down Expand Up @@ -38,10 +40,9 @@ impl U32IntoRoman of Into<u32, Roman> {
}
}

impl RomanIntoByteArray of Into<Roman, ByteArray> {
#[must_use]
fn into(self: Roman) -> ByteArray {
self.value
impl RomanDisplay of Display<Roman> {
fn fmt(self: @Roman, ref f: Formatter) -> Result<(), Error> {
write!(f, "{}", self.value)
}
}

Expand Down
54 changes: 27 additions & 27 deletions exercises/practice/roman-numerals/src/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,187 +4,187 @@ use roman_numerals::Roman;
fn number_1_is_i() {
let output: Roman = 1_u32.into();
let expected: ByteArray = "I";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_2_is_ii() {
let output: Roman = 2_u32.into();
let expected: ByteArray = "II";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_3_is_iii() {
let output: Roman = 3_u32.into();
let expected: ByteArray = "III";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_4_is_iv() {
let output: Roman = 4_u32.into();
let expected: ByteArray = "IV";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_5_is_v() {
let output: Roman = 5_u32.into();
let expected: ByteArray = "V";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_6_is_vi() {
let output: Roman = 6_u32.into();
let expected: ByteArray = "VI";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_9_is_ix() {
let output: Roman = 9_u32.into();
let expected: ByteArray = "IX";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_16_is_xvi() {
let output: Roman = 16_u32.into();
let expected: ByteArray = "XVI";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_27_is_xxvii() {
let output: Roman = 27_u32.into();
let expected: ByteArray = "XXVII";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_48_is_xlviii() {
let output: Roman = 48_u32.into();
let expected: ByteArray = "XLVIII";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_49_is_xlix() {
let output: Roman = 49_u32.into();
let expected: ByteArray = "XLIX";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_59_is_lix() {
let output: Roman = 59_u32.into();
let expected: ByteArray = "LIX";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_66_is_lxvi() {
let output: Roman = 66_u32.into();
let expected: ByteArray = "LXVI";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_93_is_xciii() {
let output: Roman = 93_u32.into();
let expected: ByteArray = "XCIII";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_141_is_cxli() {
let output: Roman = 141_u32.into();
let expected: ByteArray = "CXLI";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_163_is_clxiii() {
let output: Roman = 163_u32.into();
let expected: ByteArray = "CLXIII";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_166_is_clxvi() {
let output: Roman = 166_u32.into();
let expected: ByteArray = "CLXVI";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_402_is_cdii() {
let output: Roman = 402_u32.into();
let expected: ByteArray = "CDII";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_575_is_dlxxv() {
let output: Roman = 575_u32.into();
let expected: ByteArray = "DLXXV";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_666_is_dclxvi() {
let output: Roman = 666_u32.into();
let expected: ByteArray = "DCLXVI";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_911_is_cmxi() {
let output: Roman = 911_u32.into();
let expected: ByteArray = "CMXI";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_1024_is_mxxiv() {
let output: Roman = 1024_u32.into();
let expected: ByteArray = "MXXIV";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_1666_is_mdclxvi() {
let output: Roman = 1666_u32.into();
let expected: ByteArray = "MDCLXVI";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_3000_is_mmm() {
let output: Roman = 3000_u32.into();
let expected: ByteArray = "MMM";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_3001_is_mmmi() {
let output: Roman = 3001_u32.into();
let expected: ByteArray = "MMMI";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_3888_is_mmmdccclxxxviii() {
let output: Roman = 3888_u32.into();
let expected: ByteArray = "MMMDCCCLXXXVIII";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

#[test]
fn number_3999_is_mmmcmxcix() {
let output: Roman = 3999_u32.into();
let expected: ByteArray = "MMMCMXCIX";
assert_eq!(output.into(), expected);
assert_eq!(format!("{output}"), expected);
}

0 comments on commit 671691b

Please sign in to comment.