Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
Fewer, more clear examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
finnbear committed Mar 23, 2021
1 parent 6fe0d7a commit e021583
Showing 1 changed file with 14 additions and 31 deletions.
45 changes: 14 additions & 31 deletions moderation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"
)

func TestAnalyze(t *testing.T) {
func TestIsInappropriate(t *testing.T) {
type TestCase struct {
phrase string
offensive bool
Expand Down Expand Up @@ -90,48 +90,31 @@ func TestRedundantReplacement(t *testing.T) {
}
}

func ExampleIs_shit_profane() {
fmt.Println(Is("shit", Profane))
// Output: true
}

func ExampleIs_shit_sexual_or_mean() {
fmt.Println(Is("shit", Sexual|Mean))
// Output: false
}

func ExampleIs_caps_spam() {
fmt.Println(Is("HELLO THERE", Spam))
// Output: true
}

func ExampleIs_duuuuuuuuumb_spam() {
fmt.Println(Is("duuuuuuuuumb", Spam))
// Output: true
}

func ExampleIsInappropriate_hello() {
fmt.Println(IsInappropriate("hello"))
// Output: false
}

func ExampleIsInappropriate_sh1t() {
fmt.Println(IsInappropriate("sh1t"))
// Output: true
func ExampleIs_types() {
fmt.Println(Is("shit", Profane), Is("shit", Sexual|Mean))
fmt.Println(Is("HELLO THERE", Spam), Is("duuuuuuuuumb", Spam), Is("Normal text", Spam))
// Output:
// true false
// true true false
}

func ExampleIs_severity() {
fmt.Println(Is("sh1t", Profane), Is("sh1t", Profane&Severe))
// Output: true false
}

func ExampleIsInappropriate() {
fmt.Println(IsInappropriate("hello"), IsInappropriate("sh1t"))
// Output: false true
}

func ExampleScan() {
types := Scan("you're a dumbass")
fmt.Println(types&Profane != 0, types&Offensive != 0, types&Sexual != 0, types&Mean != 0, types&(Mean&Severe) != 0)
// Output: true false false true false
}

func TestAnalyzeWikipedia(t *testing.T) {
func TestIsInappropriateWikipedia(t *testing.T) {
wikiModerationData, err := os.Open("wikipedia-test.csv")
if err != nil {
t.Skip()
Expand All @@ -155,7 +138,7 @@ func TestAnalyzeWikipedia(t *testing.T) {
}
phrase := fields[1]
offensive := fields[0] == "1"
if Is(phrase, Profane|Offensive|Sexual|Mean) == offensive {
if IsInappropriate(phrase) == offensive {
correct++
if offensive {
correctNok++
Expand Down

0 comments on commit e021583

Please sign in to comment.