Skip to content

Implement range object #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 22, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add __eq__, __ne__ of range
__eq__ compare length, start, step of range
  • Loading branch information
HyeockJinKim committed Sep 20, 2019
commit c4de1c83ca51ed5181fa27f498a88e14f29d4c1d
55 changes: 55 additions & 0 deletions py/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,58 @@ func computeRangeLength(start, stop, step Int) Int {
var _ I__getitem__ = (*Range)(nil)
var _ I__iter__ = (*Range)(nil)
var _ I_iterator = (*RangeIterator)(nil)


func (a *Range) M__eq__(other Object) (Object, error) {
b, ok := other.(*Range)
if !ok {
return NotImplemented, nil
}

if a.Length != b.Length {
return False, nil
}

if a.Length == 0 {
return True, nil
}
if a.Start != b.Start {
return False, nil
}

if a.Step == 1 {
return True, nil
}
if a.Step != b.Step {
return False, nil
}

return True, nil
}

func (a *Range) M__ne__(other Object) (Object, error) {
b, ok := other.(*Range)
if !ok {
return NotImplemented, nil
}

if a.Length != b.Length {
return True, nil
}

if a.Length == 0 {
return False, nil
}
if a.Start != b.Start {
return True, nil
}

if a.Step == 1 {
return False, nil
}
if a.Step != b.Step {
return True, nil
}

return False, nil
}