swift - hello-world

This commit is contained in:
James Walker 2018-09-16 16:52:49 -04:00
parent 1641d23312
commit df9ede25ca
Signed by: walkah
GPG Key ID: 3C127179D6086E93
6 changed files with 84 additions and 0 deletions

4
swift/hello-world/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.DS_Store
/.build
/Packages
/*.xcodeproj

View File

@ -0,0 +1,5 @@
import PackageDescription
let package = Package(
name: "HelloWorld"
)

View File

@ -0,0 +1,29 @@
# Hello World
The classical introductory exercise. Just say "Hello, World!".
["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is
the traditional first program for beginning programming in a new language
or environment.
The objectives are simple:
- Write a function that returns the string "Hello, World!".
- Run the test suite and make sure that it succeeds.
- Submit your solution and check it at the website.
If everything goes well, you will be ready to fetch your first real exercise.
## Setup
Go through the project setup instructions for Xcode using Swift:
http://exercism.io/languages/swift
## Source
This is an exercise to introduce users to using Exercism [http://en.wikipedia.org/wiki/%22Hello,_world!%22_program](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

View File

@ -0,0 +1,6 @@
//Solution goes in Sources
class HelloWorld {
class func hello(_ name: String = "World") -> String {
return "Hello, \(name)!"
}
}

View File

@ -0,0 +1,34 @@
import XCTest
@testable import HelloWorld
class HelloWorldTests: XCTestCase {
func testNoName() {
let expected = "Hello, World!"
XCTAssertEqual(HelloWorld.hello(), expected, "When given no name, we should greet the world!")
}
func testSampleName() {
let expected = "Hello, Alice!"
XCTAssertEqual(HelloWorld.hello("Alice"), expected, "When given 'Alice' we should greet Alice!")
}
func testOtherSampleName() {
let expected = "Hello, Bob!"
XCTAssertEqual(HelloWorld.hello("Bob"), expected, "When given 'Bob' we should greet Bob!")
}
func testNoStrangeName() {
let expected = "Hello, !"
XCTAssertEqual(HelloWorld.hello(""), expected, "When given an empty string, it is strange, but should have a space and punctuation")
}
static var allTests: [(String, (HelloWorldTests) -> () throws -> Void)] {
return [
("testNoName", testNoName),
("testSampleName", testSampleName),
("testOtherSampleName", testOtherSampleName),
("testNoStrangeName", testNoStrangeName),
]
}
}

View File

@ -0,0 +1,6 @@
import XCTest
@testable import HelloWorldTests
XCTMain([
testCase(HelloWorldTests.allTests),
])