Skip to content

Conversation

@tavisit
Copy link

@tavisit tavisit commented Oct 29, 2025

Modified the operators not to create a new object each time and use a Singleton Pattern

Normal exercise passes the tests


3/1 1/3

equal(three,three)                                              : PASS
equal(third,third)                                              : PASS
equal(three,Fraction{3})                                        : PASS
equal(three,Fraction{3,1})                                      : PASS
equal(third,Fraction{1,3})                                      : PASS
equal(Fraction{3},three)                                        : PASS
equal(Fraction{1,3},third)                                      : PASS
!equal(third,Fraction{2,6})                                     : PASS
equal(third,Fraction{2,6}.normalized())                         : PASS

compare(third,Fraction{2,6})==0                                 : PASS
compare(third,Fraction{1,4})>0                                  : PASS
compare(third,Fraction{2,4})<0                                  : PASS

equal(multiply(third,2),Fraction{2,3})                          : PASS
equal(multiply(2,third),Fraction{2,3})                          : PASS
compare(multiply(three,third),Fraction{1,1})==0                 : PASS
compare(multiply(3,third),Fraction{1,1})==0                     : PASS
equal(multiply(3,third).normalized(),1)                         : PASS

Solution exercise passes the tests


3/1 1/3

three==three                                                    : PASS
third==third                                                    : PASS
three==Fraction{3}                                              : PASS
three==Fraction{3,1}                                            : PASS
third==Fraction{1,3}                                            : PASS
Fraction{3}==three                                              : PASS
Fraction{1,3}==third                                            : PASS
third!=Fraction{2,6}                                            : PASS
third==(Fraction{2,6}.normalized())                             : PASS

std::is_eq(third<=>Fraction{2,6})                               : PASS
std::is_gt(third<=>Fraction{1,4})                               : PASS
std::is_lt(third<=>Fraction{2,4})                               : PASS
third>Fraction{1,4}                                             : PASS
third<Fraction{2,4}                                             : PASS
!(third<=Fraction{1,4})                                         : PASS
!(third>=Fraction{2,4})                                         : PASS
third>=Fraction{1,4}                                            : PASS
third<=Fraction{2,4}                                            : PASS
third>=Fraction{1,3}                                            : PASS
third<=Fraction{2,3}                                            : PASS
!(third<Fraction{1,4})                                          : PASS
!(third>Fraction{2,4})                                          : PASS
!(third<Fraction{1,3})                                          : PASS
!(third>Fraction{2,3})                                          : PASS

(third*2)==Fraction{2,3}                                        : PASS
(2*third)==Fraction{2,3}                                        : PASS
std::is_eq((three*third)<=>Fraction{1,1})                       : PASS
std::is_eq((3*third)<=>Fraction{1,1})                           : PASS
(3*third).normalized()==1                                       : PASS

std::is_eq(one<=>1)                                             : PASS
one.normalized()==1                                             : PASS
one!=1                                                          : PASS

@tavisit tavisit closed this Oct 29, 2025
@tavisit tavisit deleted the operators_without_init_printer branch October 30, 2025 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant