aboutsummaryrefslogtreecommitdiff
path: root/main_test.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-23 02:11:41 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-23 03:54:33 +0800
commite68745e4cb31e6d6cde7b7c1c84b39d862a7d19d (patch)
tree69203b33397d67388bb278ab8c7c178e89f8399b /main_test.go
parentBasic reverse proxy (diff)
downloadpowxy-e68745e4cb31e6d6cde7b7c1c84b39d862a7d19d.tar.gz
powxy-e68745e4cb31e6d6cde7b7c1c84b39d862a7d19d.tar.zst
powxy-e68745e4cb31e6d6cde7b7c1c84b39d862a7d19d.zip
Basic proof of work
Diffstat (limited to '')
-rw-r--r--main_test.go90
1 files changed, 90 insertions, 0 deletions
diff --git a/main_test.go b/main_test.go
new file mode 100644
index 0000000..394d407
--- /dev/null
+++ b/main_test.go
@@ -0,0 +1,90 @@
+package main
+
+import (
+ "testing"
+)
+
+func TestValidateBitZeros(t *testing.T) {
+ tests := []struct {
+ name string
+ bs []byte
+ n uint
+ expected bool
+ }{
+ {
+ name: "First 8 bits are zeros",
+ bs: []byte{0x00, 0x01},
+ n: 8,
+ expected: true,
+ },
+ {
+ name: "First 8 bits are not all zeros",
+ bs: []byte{0x01, 0x00},
+ n: 8,
+ expected: false,
+ },
+ {
+ name: "First 16 bits are zeros",
+ bs: []byte{0x00, 0x00, 0x01},
+ n: 16,
+ expected: true,
+ },
+ {
+ name: "First 16 bits are not all zeros",
+ bs: []byte{0x01, 0x00, 0x00},
+ n: 16,
+ expected: false,
+ },
+ {
+ name: "First 9 bits are zeros",
+ bs: []byte{0x00, 0x01},
+ n: 9,
+ expected: true,
+ },
+ {
+ name: "First 9 bits are not all zeros",
+ bs: []byte{0x01, 0x01},
+ n: 9,
+ expected: false,
+ },
+ {
+ name: "First 10 bits are zeros",
+ bs: []byte{0x00, 0x20},
+ n: 10,
+ expected: true,
+ },
+ {
+ name: "First 10 bits are not all zeros",
+ bs: []byte{0x00, 0x40},
+ n: 10,
+ expected: false,
+ },
+ {
+ name: "First 24 bits are zeros",
+ bs: []byte{0x00, 0x00, 0x00, 0x01},
+ n: 24,
+ expected: true,
+ },
+ {
+ name: "First 24 bits are not all zeros",
+ bs: []byte{0x00, 0x01, 0x00, 0x00},
+ n: 24,
+ expected: false,
+ },
+ {
+ name: "Checking zero bits",
+ bs: []byte{0xFF, 0xFF},
+ n: 0,
+ expected: true,
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got := validateBitZeros(tt.bs, tt.n)
+ if got != tt.expected {
+ t.Errorf("validateBitZeros(%v, %v) = %v; want %v", tt.bs, tt.n, got, tt.expected)
+ }
+ })
+ }
+}