summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flood.go11
-rw-r--r--flood_test.go8
2 files changed, 7 insertions, 12 deletions
diff --git a/flood.go b/flood.go
index 21acb47..42b970e 100644
--- a/flood.go
+++ b/flood.go
@@ -26,7 +26,7 @@ func Flood(s string) bool {
return false
}
if v := strings.Fields(s); len(v) >= 6 {
- return CommonWord(v) >= 2*len(v)/3 || MedianLength(v) == 1
+ return CommonWord(v) >= len(v)/2
}
return Entropy(s) <= 1
}
@@ -44,15 +44,6 @@ func CommonWord(v []string) int {
return l[0]
}
-func MedianLength(v []string) int {
- l := make([]int, len(v))
- for i, s := range v {
- l[i] = len(s)
- }
- sort.Sort(sort.IntSlice(l))
- return l[len(l)/2]
-}
-
func DetectFlood(conn *irc.Conn, line *irc.Line) {
if Flood(line.Text()) {
log.Println("flood", line.Nick)
diff --git a/flood_test.go b/flood_test.go
index 3e16db4..c2e087b 100644
--- a/flood_test.go
+++ b/flood_test.go
@@ -22,7 +22,7 @@ var floodTestData = []floodTest{
},
{
Input: `a b c d e f g h i j`,
- Result: true,
+ Result: false,
},
{
Input: `const union __infinity_un __infinity = { { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f } };`,
@@ -30,7 +30,7 @@ var floodTestData = []floodTest{
},
{
Input: `a = b > 3 ? 2 : 4`,
- Result: true,
+ Result: false,
},
{
Input: `AAAAAAAAAAAAAAAAAAAA`,
@@ -40,6 +40,10 @@ var floodTestData = []floodTest{
Input: `AAAAAAAAAABBBBBBBBBB`,
Result: true,
},
+ {
+ Input: `ivy 3 3 rho (iota 9) in 2 6 7 8 9`,
+ Result: false,
+ },
}
func TestFlood(t *testing.T) {