package tweeter import ( "testing" ts "github.com/imperatrona/twitter-scraper" ) func TestFilter(t *testing.T) { filter1 := []uint8{0b10101, 0b11111, 0b00000, 0b00111, 0b00101, 0b00001, 0b10111, 0b10101, 0b01101, 0b10101} filter2 := []uint8{0b10101, 0b11111, 0b00000, 0b00111, 0b00101, 0b00001, 0b01000, 0b01010, 0b01000, 0b11011} filterR := []uint8{0b10101, 0b11111, 0b00000, 0b00111, 0b00101, 0b00001, 0b00000, 0b00000, 0b01000, 0b10001} filterB := []bool{true, true, false, true, true, true, false, false, true, true} for i, filterBool := range filterB { filterResult := filterR[i] filterCheck := filter2[i] filterQuoted := (filterCheck & 1) != 0 // first bit filterPin := (filterCheck & 2) != 0 // second bit filterReply := (filterCheck & 4) != 0 // third bit filterRetweet := (filterCheck & 8) != 0 // fourth bit filterSelfThread := (filterCheck & 16) != 0 // fifth bit tweet := ts.Tweet{ IsSelfThread: filterSelfThread, IsRetweet: filterRetweet, IsReply: filterReply, IsPin: filterPin, IsQuoted: filterQuoted, } resultBool := filterTweet(filter1[i], &tweet) if resultBool != filterBool { t.Errorf("%b AND %b > 0 = %t; got %t\n", filter1[i], filter2[i], filterBool, resultBool) } resultByte := filterByte(filter1[i], &tweet) if resultByte != filterResult { t.Errorf("%b AND %b = %b; got %b\n", filter1[i], filter2[i], filterResult, resultByte) } } }