mirror of
https://gogs.blitter.com/RLabs/xs
synced 2024-08-14 10:26:42 +00:00
MSYS+mintty support; pkg renaming to hkexsh
This commit is contained in:
parent
dd746cf343
commit
5da70447b0
15 changed files with 281 additions and 377 deletions
55
spinsult/spinsult.go
Normal file
55
spinsult/spinsult.go
Normal file
|
@ -0,0 +1,55 @@
|
|||
// A golang translation of a 'Shakespeare insult generator'
|
||||
// Originally from http://www.mainstrike.com/mstservices/handy/insult.html
|
||||
package spinsult
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
r *rand.Rand
|
||||
|
||||
phrase1 = [...]string{
|
||||
"artless", "bawdy", "beslubbering", "bootless", "churlish", "clouted",
|
||||
"cockered", "craven", "currish", "dankish", "dissembling", "droning", "errant", "fawning",
|
||||
"fobbing", "frothy", "froward", "gleeking", "goatish", "gorbellied", "impertinent",
|
||||
"infectious", "jarring", "loggerheaded", "lumpish", "mammering", "mangled", "mewling",
|
||||
"paunchy", "pribbling", "puking", "puny", "qualling", "rank", "reeky", "roguish", "ruttish",
|
||||
"saucy", "spleeny", "spongy", "surly", "tottering", "unmuzzled", "vain", "venomed",
|
||||
"villainous", "warped", "wayward", "weedy", "yeasty"}
|
||||
|
||||
phrase2 = [...]string{"base-court", "bat-fowling", "beef-witted", "beetle-headed",
|
||||
"boil-brained", "clapper-clawed", "clay-brained", "common-kissing", "crook-pated",
|
||||
"dismal-dreaming", "dizzy-eyed", "doghearted", "dread-bolted", "earth-vexing",
|
||||
"elf-skinned", "fat-kidneyed", "fen-sucked", "flap-mouthed", "fly-bitten",
|
||||
"folly-fallen", "fool-born", "full-gorged", "guts-griping", "half-faced", "hasty-witted",
|
||||
"hedge-born", "hell-hated", "idle-headed", "ill-breeding", "ill-nurtured", "knotty-pated",
|
||||
"milk-livered", "motley-minded", "onion-eyed", "plume-plucked", "pottle-deep",
|
||||
"pox-marked", "reeling-ripe", "rough-hewn", "rude-growing", "rump-fed", "shard-borne",
|
||||
"sheep-biting", "spur-galled", "swag-bellied", "tardy-gaited", "tickle-brained",
|
||||
"toad-spotted", "urchin-snouted", "weather-bitten"}
|
||||
|
||||
phrase3 = [...]string{"apple-john", "baggage", "barnacle", "bladder", "boar-pig", "bugbear",
|
||||
"bum-bailey", "canker-blossom", "clack-dish", "clotpole", "codpiece", "coxcomb", "death-token",
|
||||
"dewberry", "flap-dragon", "flax-wench", "flirt-gill", "foot-licker", "fustilarian",
|
||||
"giglet", "gudgeon", "haggard", "harpy", "hedge-pig", "horn-beast", "hugger-mugger",
|
||||
"joithead", "lewdster", "lout", "maggot-pie", "malt-worm", "mammet", "measle", "minnow",
|
||||
"miscreant", "moldwarp", "mumble-news", "nut-hook", "pigeon-egg", "pignut", "pumpion",
|
||||
"puttock", "ratsbane", "scut", "skainsmate", "strumpet", "varlet", "vassal", "wagtail",
|
||||
"whey-face"}
|
||||
)
|
||||
|
||||
func GetSentence() (ret string) {
|
||||
return "Thou " + Get()
|
||||
}
|
||||
|
||||
func Get() (ret string) {
|
||||
if r == nil {
|
||||
r = rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
}
|
||||
ret = phrase1[r.Int()%len(phrase1)] + " " +
|
||||
phrase2[r.Int()%len(phrase2)] + " " +
|
||||
phrase3[r.Int()%len(phrase3)] + "!"
|
||||
return
|
||||
}
|
52
spinsult/spinsult_test.go
Normal file
52
spinsult/spinsult_test.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
//To show coverage for tests:
|
||||
//
|
||||
//1. go test -coverprofile=cov.out
|
||||
//2. go tool cover -func=cov.out
|
||||
//3. go tool cover -html=cov.out
|
||||
//4. Profit!!
|
||||
//
|
||||
// For heatmap coverage, change step 1 to:
|
||||
//2. go test -covermode=count -coverprofile=cov.out
|
||||
//
|
||||
// ref: https://blog.golang.org/cover
|
||||
|
||||
package spinsult
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test1Get(t *testing.T) {
|
||||
//if testing.Short() {
|
||||
// t.Skip("skipping test in short mode.")
|
||||
//}
|
||||
r = rand.New(rand.NewSource(42))
|
||||
out := Get()
|
||||
if out != "mammering doghearted codpiece!" {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func Test2Get(t *testing.T) {
|
||||
//if testing.Short() {
|
||||
// t.Skip("skipping test in short mode.")
|
||||
//}
|
||||
out := Get()
|
||||
if out != "dankish common-kissing coxcomb!" {
|
||||
t.Fail()
|
||||
}
|
||||
out = GetSentence()
|
||||
if out != "Thou wayward crook-pated fustilarian!" {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
// Example of calling Get() for a random insult.
|
||||
func ExampleGet() {
|
||||
r = rand.New(rand.NewSource(42))
|
||||
out := GetSentence()
|
||||
fmt.Println(out)
|
||||
//Output: Thou mammering doghearted codpiece!
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue