Basic 001 Bob

Instructions

Bob is a lackadaisical teenager. In conversation, his responses are very limited.
Bob answers 'Sure.' if you ask him a question.
He answers 'Whoa, chill out!' if you yell at him.
He says 'Fine. Be that way!' if you address him without actually saying anything.
He answers 'Whatever.' to anything else.

C# Test

  1 // This file was auto-generated based on version 1.0.0 of the canonical data.
  2 
  3 using Xunit;
  4 
  5 public class BobTest
  6 {
  7     [Fact]
  8     public void Stating_something()
  9     {
 10         Assert.Equal("Whatever.", Bob.Response("Tom-ay-to, tom-aaaah-to."));
 11     }
 12 
 13     [Fact(Skip = "Remove to run test")]
 14     public void Shouting()
 15     {
 16         Assert.Equal("Whoa, chill out!", Bob.Response("WATCH OUT!"));
 17     }
 18 
 19     [Fact(Skip = "Remove to run test")]
 20     public void Shouting_gibberish()
 21     {
 22         Assert.Equal("Whoa, chill out!", Bob.Response("FCECDFCAAB"));
 23     }
 24 
 25     [Fact(Skip = "Remove to run test")]
 26     public void Asking_a_question()
 27     {
 28         Assert.Equal("Sure.", Bob.Response("Does this cryogenic chamber make me look fat?"));
 29     }
 30 
 31     [Fact(Skip = "Remove to run test")]
 32     public void Asking_a_numeric_question()
 33     {
 34         Assert.Equal("Sure.", Bob.Response("You are, what, like 15?"));
 35     }
 36 
 37     [Fact(Skip = "Remove to run test")]
 38     public void Asking_gibberish()
 39     {
 40         Assert.Equal("Sure.", Bob.Response("fffbbcbeab?"));
 41     }
 42 
 43     [Fact(Skip = "Remove to run test")]
 44     public void Talking_forcefully()
 45     {
 46         Assert.Equal("Whatever.", Bob.Response("Let's go make out behind the gym!"));
 47     }
 48 
 49     [Fact(Skip = "Remove to run test")]
 50     public void Using_acronyms_in_regular_speech()
 51     {
 52         Assert.Equal("Whatever.", Bob.Response("It's OK if you don't want to go to the DMV."));
 53     }
 54 
 55     [Fact(Skip = "Remove to run test")]
 56     public void Forceful_question()
 57     {
 58         Assert.Equal("Whoa, chill out!", Bob.Response("WHAT THE HELL WERE YOU THINKING?"));
 59     }
 60 
 61     [Fact(Skip = "Remove to run test")]
 62     public void Shouting_numbers()
 63     {
 64         Assert.Equal("Whoa, chill out!", Bob.Response("1, 2, 3 GO!"));
 65     }
 66 
 67     [Fact(Skip = "Remove to run test")]
 68     public void Only_numbers()
 69     {
 70         Assert.Equal("Whatever.", Bob.Response("1, 2, 3"));
 71     }
 72 
 73     [Fact(Skip = "Remove to run test")]
 74     public void Question_with_only_numbers()
 75     {
 76         Assert.Equal("Sure.", Bob.Response("4?"));
 77     }
 78 
 79     [Fact(Skip = "Remove to run test")]
 80     public void Shouting_with_special_characters()
 81     {
 82         Assert.Equal("Whoa, chill out!", Bob.Response("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"));
 83     }
 84 
 85     [Fact(Skip = "Remove to run test")]
 86     public void Shouting_with_no_exclamation_mark()
 87     {
 88         Assert.Equal("Whoa, chill out!", Bob.Response("I HATE YOU"));
 89     }
 90 
 91     [Fact(Skip = "Remove to run test")]
 92     public void Statement_containing_question_mark()
 93     {
 94         Assert.Equal("Whatever.", Bob.Response("Ending with ? means a question."));
 95     }
 96 
 97     [Fact(Skip = "Remove to run test")]
 98     public void Non_letters_with_question()
 99     {
100         Assert.Equal("Sure.", Bob.Response(":) ?"));
101     }
102 
103     [Fact(Skip = "Remove to run test")]
104     public void Prattling_on()
105     {
106         Assert.Equal("Sure.", Bob.Response("Wait! Hang on. Are you going to be OK?"));
107     }
108 
109     [Fact(Skip = "Remove to run test")]
110     public void Silence()
111     {
112         Assert.Equal("Fine. Be that way!", Bob.Response(""));
113     }
114 
115     [Fact(Skip = "Remove to run test")]
116     public void Prolonged_silence()
117     {
118         Assert.Equal("Fine. Be that way!", Bob.Response("          "));
119     }
120 
121     [Fact(Skip = "Remove to run test")]
122     public void Alternate_silence()
123     {
124         Assert.Equal("Fine. Be that way!", Bob.Response("\t\t\t\t\t\t\t\t\t\t"));
125     }
126 
127     [Fact(Skip = "Remove to run test")]
128     public void Multiple_line_question()
129     {
130         Assert.Equal("Whatever.", Bob.Response("\nDoes this cryogenic chamber make me look fat?\nno"));
131     }
132 
133     [Fact(Skip = "Remove to run test")]
134     public void Starting_with_whitespace()
135     {
136         Assert.Equal("Whatever.", Bob.Response("         hmmmmmmm..."));
137     }
138 
139     [Fact(Skip = "Remove to run test")]
140     public void Ending_with_whitespace()
141     {
142         Assert.Equal("Sure.", Bob.Response("Okay if like my  spacebar  quite a bit?   "));
143     }
144 
145     [Fact(Skip = "Remove to run test")]
146     public void Other_whitespace()
147     {
148         Assert.Equal("Fine. Be that way!", Bob.Response("\n\r \t"));
149     }
150 
151     [Fact(Skip = "Remove to run test")]
152     public void Non_question_ending_with_whitespace()
153     {
154         Assert.Equal("Whatever.", Bob.Response("This is a statement ending with whitespace      "));
155     }
156 }
View Code 

C# Solution

 1 using System;
 2 
 3 /*
 4 question: last character is '?'
 5 answer: "Sure."
 6 
 7 yell: all characters are uppercase
 8 answer: "Whoa, chill out!"
 9 
10 silence: empty
11 answer: "Fine. Be that way!"
12 
13 default
14 answer: "Whatever"
15 
16  */
17 public static class Bob
18 {
19     public static string Response(string statement)
20     {
21         if (statement.Trim().EndsWith('?'))
22         {
23             return "Sure.";
24         }
25         if (statement.ToUpper() == statement)
26         {
27             return "Whoa, chill out!";
28         }
29         if (statement.Trim() == "")
30         {
31             return "Fine. Be that way!";
32         }
33         return "Whatever.";
34 
35     }
36 }
View Code

 

posted @ 2017-12-05 00:21  jarodli  阅读(110)  评论(0编辑  收藏  举报