Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ex01/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/xiote/Exercises-for-Programmers

go 1.14

require github.com/stretchr/testify v1.6.1
34 changes: 34 additions & 0 deletions ex01/go/xiote.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 작성자 : 한진우
// 실행방법 : go run xiote.go
// 주의사항 :

package main

import (
"bufio"
"fmt"
"os"
)

func main() {
fmt.Print("What is your name? ")
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
person := scanner.Text()
hello := NewHello(person)
fmt.Println(hello.Message())
return
}
}

func NewHello(person string) Hello {
return Hello{person}
}

type Hello struct {
Person string
}

func (h *Hello) Message() string {
return fmt.Sprintf("Hello, %s, nice to meet you!", h.Person)
}
20 changes: 20 additions & 0 deletions ex01/go/xiote_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestSample(t *testing.T) {
assert := assert.New(t)

assert.Equal(1, 1)
}

func TestHelloMessage(t *testing.T) {
assert := assert.New(t)

hello := NewHello("Brian")
message := hello.Message()
assert.Equal(message, "Hello, Brian, nice to meet you!")
}