Skip to content

Instantly share code, notes, and snippets.

@nsa-yoda
Last active October 18, 2020 21:23
Show Gist options
  • Save nsa-yoda/0b61c8d7bae4d1fcf232dd048b61d166 to your computer and use it in GitHub Desktop.
Save nsa-yoda/0b61c8d7bae4d1fcf232dd048b61d166 to your computer and use it in GitHub Desktop.
Written as a joke...convoluted boolean comparison
package main
import (
"errors"
"fmt"
)
type BoolCompare struct {
left bool
right bool
comparison bool
wasCompared int16
}
func (b *BoolCompare) SetLeft(left bool) {
b.left = bool
}
func (b *BoolCompare) SetRight(right bool) {
b.right = bool
}
func (b *BoolCompare) SetComparison() {
b.comparison = b.Compare()
b.wasCompared = b.wasCompared + 1
}
func (b *BoolCompare) GetEquality() (bool, error) {
if b.wasCompared == 0 {
return false, errors.New("booleans have not been compared yet")
}
return b.comparison, nil
}
func (b *BoolCompare) Compare() bool {
if b.left == b.right {
return true
}
return b.CompareAgainToMakeSure()
}
func (b *BoolCompare) CompareAgainToMakeSure() bool {
if b.left == true && b.right == true {
return true
}
if b.left == false && b.right == false {
return true
}
return false
}
func main() {
b := BoolCompare{}
b.SetLeft(true)
b.SetRight(false)
b.SetComparison()
equal, err := b.GetEquality()
if err != nil {
}
fmt.Println(equal)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment