swift - hello-world
This commit is contained in:
parent
1641d23312
commit
df9ede25ca
4
swift/hello-world/.gitignore
vendored
Normal file
4
swift/hello-world/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.DS_Store
|
||||||
|
/.build
|
||||||
|
/Packages
|
||||||
|
/*.xcodeproj
|
5
swift/hello-world/Package.swift
Normal file
5
swift/hello-world/Package.swift
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import PackageDescription
|
||||||
|
|
||||||
|
let package = Package(
|
||||||
|
name: "HelloWorld"
|
||||||
|
)
|
29
swift/hello-world/README.md
Normal file
29
swift/hello-world/README.md
Normal 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.
|
6
swift/hello-world/Sources/HelloWorld.swift
Normal file
6
swift/hello-world/Sources/HelloWorld.swift
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
//Solution goes in Sources
|
||||||
|
class HelloWorld {
|
||||||
|
class func hello(_ name: String = "World") -> String {
|
||||||
|
return "Hello, \(name)!"
|
||||||
|
}
|
||||||
|
}
|
@ -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),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
6
swift/hello-world/Tests/LinuxMain.swift
Normal file
6
swift/hello-world/Tests/LinuxMain.swift
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import XCTest
|
||||||
|
@testable import HelloWorldTests
|
||||||
|
|
||||||
|
XCTMain([
|
||||||
|
testCase(HelloWorldTests.allTests),
|
||||||
|
])
|
Loading…
x
Reference in New Issue
Block a user