Last active
October 18, 2020 21:23
-
-
Save nsa-yoda/0b61c8d7bae4d1fcf232dd048b61d166 to your computer and use it in GitHub Desktop.
Written as a joke...convoluted boolean comparison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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