Skip to content

Commit

Permalink
Merge pull request #3 from ChloeParry23/master
Browse files Browse the repository at this point in the history
Fixed Code
  • Loading branch information
broomyocymru authored Nov 14, 2019
2 parents 36d7961 + f8bd087 commit e19385a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.capgemini.tdd.demo.models.Greeting;

import com.capgemini.tdd.demo.models.TalkyNumber;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -19,4 +20,12 @@ public Greeting greeting(@RequestParam(value="name", defaultValue="World") Strin
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}


@RequestMapping("/talkynumbers")
public TalkyNumber talkynumbers(@RequestParam(value = "number", defaultValue = "1") String number) {
return new TalkyNumber(counter.incrementAndGet(),
Integer.parseInt(number));
}
}

24 changes: 24 additions & 0 deletions src/main/java/com/capgemini/tdd/demo/models/TalkyNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.capgemini.tdd.demo.models;

import com.capgemini.tdd.demo.services.NumberService;

public class TalkyNumber {
private final long id;
private final int number;
private NumberService talkynumbers = new NumberService();

public TalkyNumber(long id, int number) {
this.id = id;
this.number= number;
}

public long getId() {
return id;
}

public String getNumber() {
return talkynumbers.convert(number);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public NumberService(){
digits.put(4,"Four");
digits.put(5,"Five");
digits.put(6,"Six");
digits.put(7,"Severn");
digits.put(7,"Seven");
digits.put(8,"Eight");
digits.put(9,"Nine");
digits.put(10,"Ten");
Expand Down Expand Up @@ -68,7 +68,7 @@ public String convert(int num){
if(num >= 100){
output += ", ";
}
else{
else if (num > 0) {
output += " and ";
}

Expand Down
4 changes: 3 additions & 1 deletion src/test/java/com/capgemini/tdd/demo/NumberServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ void convert3282(){
@Test
void convert0To9999(){
int i = 0;
while(i<999){
while(i<9999){
System.out.println(service.convert(i));
i++;
}
assertEquals("Nine Hundred and Ninety Nine", service.convert(999));
}
@Test
void convert1000(){ assertEquals("One Thousand", service.convert(1000));}

}

0 comments on commit e19385a

Please sign in to comment.