Skip to content

Commit

Permalink
Added more test, changed for real JSON library
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTipo01 committed Apr 10, 2021
1 parent ec0238a commit edb2e5c
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 3 deletions.
24 changes: 24 additions & 0 deletions emoji_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"strings"
"testing"
)

func TestEmojiReplacer(t *testing.T) {
emoji = *emojiReplacer()

if &emoji == nil {
t.Error("Emoji replacer is empty")
}
}

func TestEmojiToDescription(t *testing.T) {
if &emoji == nil {
emoji = *emojiReplacer()
}

if strings.ToLower(emoji.Replace("🕴️")) != "uomo con completo che levita" {
t.Error("Emoji replacer gave wrong description")
}
}
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ func init() {
break
}

// Read adjective
foo, _ := ioutil.ReadFile("parole.txt")
adjectives = strings.Split(string(foo), "\n")
initializeAdjectives()

// Initialize rand
rand.Seed(time.Now().Unix())
Expand Down Expand Up @@ -163,3 +161,9 @@ func ready(s *discordgo.Session, _ *discordgo.Ready) {
func guildCreate(_ *discordgo.Session, e *discordgo.GuildCreate) {
initializeServer(e.Guild.ID)
}

// Reads adjectives
func initializeAdjectives() {
foo, _ := ioutil.ReadFile("parole.txt")
adjectives = strings.Split(string(foo), "\n")
}
61 changes: 61 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"os"
"runtime"
"strings"
"testing"
)

func BenchmarkBestemmia(b *testing.B) {
// Read adjectives if they are not loaded before
if len(adjectives) == 0 {
initializeAdjectives()
}

for i := 0; i < b.N; i++ {
bestemmia()
}
}

func TestInitializeAdjectives(t *testing.T) {
initializeAdjectives()

if len(adjectives) == 0 {
t.Error("Adjectives slice is empty")
}
}

func TestBestemmia(t *testing.T) {
// Read adjectives if they are not loaded before
if len(adjectives) == 0 {
initializeAdjectives()
}

if strings.TrimSpace(bestemmia()) == "" {
t.Error("Generated string is empty")
}
}

func TestGenAudio(t *testing.T) {
if runtime.GOOS == "windows" {
_ = os.Remove("./temp/NP5M2VS4G9AQEEIPC6V6DQH5J1RGS4PE.dca")
uuid := genAudio("AGAGAGAGAGA")
stat, err := os.Stat("./temp/NP5M2VS4G9AQEEIPC6V6DQH5J1RGS4PE.dca")

if uuid != "NP5M2VS4G9AQEEIPC6V6DQH5J1RGS4PE.dca" {
t.Error("Hash mismatch")
} else {
if err != nil {
t.Error("File doesn't exist")
} else {
if !(stat.Size() > 0) {
t.Error("File is empty")
}
}
}
} else {
t.Skip("Audio generation is only supported by windows")
}

}

0 comments on commit edb2e5c

Please sign in to comment.