Hello World


Just thought I’d write up a quick method to return “Hello World!” in two of my favorite programming languages. Plus I wrote down some unit test for good measure. Because no method is complete without some test right?

C#

public static string SayHello(string language = english)
{
if(language == “english”)
return “Hello World!”;
else
return string.Format(“I don’t speak {0}.”, language);
}

NUnit Test

“`
[Test]
public void HelloEnglish()
{
Assert.AreEqual(“Hello World!”, SayHello());
}

[Test]
public void DoNotSpeakEbonics()
{
Assert.AreEqual(“I don’t speak ebonics”, SayHello(“ebonics”))
}
“`

Java

public static String sayHello(String language)
{
if(language == “english”)
return “Hello World!”;
else
return String.format(“I don’t speak %s.”, language);
}

JUnit Test

“`
@Test
public void helloEnglish() {
assertEquals(“Hello World!”, sayHello(“english”));
}

@Test
public void doNotSpeakEbonics() {
assertEquals(“I don’t speak ebonics”, sayHello(“ebonics”));
}
“`


Leave a Reply

Your email address will not be published. Required fields are marked *