Skip to content

Fix issue 325 by adding algo for equals() #412

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 7 commits into from
Jun 30, 2017
Merged

Conversation

nainar
Copy link
Contributor

@nainar nainar commented Jun 5, 2017

@shans could you take a look, took a stab at writing up the algo for .equals()

when called on a {{CSSNumericValue}} |this|,
must perform the following steps:

1. If the |value| item is the same type as the {{CSSNumericValue}} the method is being called on continue to step 2, else return false.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to continue on to step 2 as this happens automatically. Maybe rewrite as 'If |value| is of different type to |this|, return false.'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we need to define what 'different type' means.

The <dfn for=CSSNumericValue method>equals(...|value|)</dfn> method,
when called on a {{CSSNumericValue}} |this|,
must perform the following steps:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need to either explicitly iterate over |value| (change to values?) or just restrict this to take a single value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And by "or" Shane means "do the first thing", because all the other methods take multiple values too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had done the first thing. Commit 3 should make equals accept an array.


1. If the |value| item is the same type as the {{CSSNumericValue}} the method is being called on continue to step 2, else return false.

2. If the |value| item has the same type as the {{CSSNumericValue}} continue to the next step, else return false.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this the same as step 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was supposed to be class.

2. If the |value| item has the same type as the {{CSSNumericValue}} continue to the next step, else return false.

3. If the |value| item has the same unit as the {{CSSNumericValue}} return true, else return false.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need to handle calc values, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 3

<div class=issue>
Define {{CSSNumericValue/equals()}}.
<div algorithm="CSSNumericValue.equals(...|value|)">
The <dfn for=CSSNumericValue method>equals(...|value|)</dfn> method,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that .equals() is variadic; you have to check that all the values are equal to each other/this.

when called on a {{CSSNumericValue}} |this|,
must perform the following steps:

1. If the |value| item is the same type as the {{CSSNumericValue}} the method is being called on continue to step 2, else return false.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Just reverse this conditional and return false. No need to explicitly say to go to the next step; that's implied by the list.
  • Be clear what you mean by "type" - you use the exact same word in the second step, but clearly mean something different. I suspect here you're talking about the interface type.
  • "the CSSNumericValue the method is being called on" is already stored in the |this| variable, so you just refer to it that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 3


1. If the |value| item is the same type as the {{CSSNumericValue}} the method is being called on continue to step 2, else return false.

2. If the |value| item has the same type as the {{CSSNumericValue}} continue to the next step, else return false.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Same concerns as about the structure; reverse the conditional and just return false.
  • I think you mean "value" here? Refer to |this|’s {{CSSUnitValue/value}} internal slot then (and same for |value|).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 3


2. If the |value| item has the same type as the {{CSSNumericValue}} continue to the next step, else return false.

3. If the |value| item has the same unit as the {{CSSNumericValue}} return true, else return false.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use {{CSSUnitValue/unit}} internal slot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 3

<div algorithm="CSSNumericValue.equals(...|value|)">
The <dfn for=CSSNumericValue method>equals(...|value|)</dfn> method,
when called on a {{CSSNumericValue}} |this|,
must perform the following steps:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The algo claims to be defined for CSSNumericValue, but the steps assume that you're looking at a CSSUnitValue. It needs to work for all the CSSMathValue subtypes too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 3

@tabatkins
Copy link
Member

Whoops, I still had this page up from earlier, and it hadn't updated with Shane's comments. Sorry for doubling up. ^_^

@nainar
Copy link
Contributor Author

nainar commented Jun 6, 2017

I suck at Github but I have added a new commit. Hopefully that addresses both @shans and @tabatkins comments.

Copy link
Contributor Author

@nainar nainar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit 3 makes equals accept an array of values instead of just one value. Take a look?

<div algorithm="CSSNumericValue.equals(...|value|)">
The <dfn for=CSSNumericValue method>equals(...|value|)</dfn> method,
when called on a {{CSSNumericValue}} |this|,
must perform the following steps:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 3

The <dfn for=CSSNumericValue method>equals(...|value|)</dfn> method,
when called on a {{CSSNumericValue}} |this|,
must perform the following steps:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had done the first thing. Commit 3 should make equals accept an array.

2. If the |value| item has the same type as the {{CSSNumericValue}} continue to the next step, else return false.

3. If the |value| item has the same unit as the {{CSSNumericValue}} return true, else return false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 3

when called on a {{CSSNumericValue}} |this|,
must perform the following steps:

1. If the |value| item is the same type as the {{CSSNumericValue}} the method is being called on continue to step 2, else return false.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 3


1. If the |value| item is the same type as the {{CSSNumericValue}} the method is being called on continue to step 2, else return false.

2. If the |value| item has the same type as the {{CSSNumericValue}} continue to the next step, else return false.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 3


2. If the |value| item has the same type as the {{CSSNumericValue}} continue to the next step, else return false.

3. If the |value| item has the same unit as the {{CSSNumericValue}} return true, else return false.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 3

Copy link
Member

@tabatkins tabatkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking much better overall, just some nits left.


1. [=list/If all=] |item|s of |thisAndValues| do not belong to the same class return false. Example: all items in |thisAndValues| must be {{CSSUnitValue}}.

2. [=list/If all=] |item|s in |thisAndValues| are {{CSSUnitValue}s and have the same {{CSSUnitValue/value}} return true.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit and value ^_^

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


2. [=list/If all=] |item|s in |thisAndValues| are {{CSSUnitValue}s and have the same {{CSSUnitValue/value}} return true.

4. =list/If all=] |item|s in |thisAndValues| are {{CSSMathValue}s :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing [

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

2. [=list/If all=] |item|s in |thisAndValues| are {{CSSUnitValue}s and have the same {{CSSUnitValue/value}} return true.

4. =list/If all=] |item|s in |thisAndValues| are {{CSSMathValue}s :
1. If the {{CSSMathValue/operator}} are not equal for all {{CSSMathValues}} in |thisAndValues| return false.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already covered by "same class" earlier, so you can drop this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

1. If the {{CSSMathValue/operator}} are not equal for all {{CSSMathValues}} in |thisAndValues| return false.
2. If |thisAndValues| are all either {{CSSMathSum}}, {{CSSMathProduct}}, {{CSSMathMin}} or {{CSSMathMax}}, iterate over the {{CSSNumericArray}}s on |thisAndValues|,
1. For each {{CSSUnitValue}} in each of the {{CSSNumericArray}}s go back to step 1 to check that the {{CSSUnitValue}}s on all items in |thisAndValue| are equal.
3. If |this| and |value| are both either {{CSSMathNegate}} or {{CSSMathInvert}}:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to handle multiples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean CSSMathProduct? Cause that is dealt with in the above step. Or do you mean the case where values in |thisAndValues| are not all of the same type? If the latter in that case we should return a false right?

@nainar
Copy link
Contributor Author

nainar commented Jun 9, 2017

@tabatkins took a stab at equals take a look?

@nainar nainar changed the title Fix issue 325 Fix issue 325 by adding algo for equals() Jun 9, 2017
Copy link
Contributor Author

@nainar nainar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tabatkins made the changes and had a follow up question.


1. [=list/If all=] |item|s of |thisAndValues| do not belong to the same class return false. Example: all items in |thisAndValues| must be {{CSSUnitValue}}.

2. [=list/If all=] |item|s in |thisAndValues| are {{CSSUnitValue}s and have the same {{CSSUnitValue/value}} return true.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


2. [=list/If all=] |item|s in |thisAndValues| are {{CSSUnitValue}s and have the same {{CSSUnitValue/value}} return true.

4. =list/If all=] |item|s in |thisAndValues| are {{CSSMathValue}s :
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

2. [=list/If all=] |item|s in |thisAndValues| are {{CSSUnitValue}s and have the same {{CSSUnitValue/value}} return true.

4. =list/If all=] |item|s in |thisAndValues| are {{CSSMathValue}s :
1. If the {{CSSMathValue/operator}} are not equal for all {{CSSMathValues}} in |thisAndValues| return false.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

1. If the {{CSSMathValue/operator}} are not equal for all {{CSSMathValues}} in |thisAndValues| return false.
2. If |thisAndValues| are all either {{CSSMathSum}}, {{CSSMathProduct}}, {{CSSMathMin}} or {{CSSMathMax}}, iterate over the {{CSSNumericArray}}s on |thisAndValues|,
1. For each {{CSSUnitValue}} in each of the {{CSSNumericArray}}s go back to step 1 to check that the {{CSSUnitValue}}s on all items in |thisAndValue| are equal.
3. If |this| and |value| are both either {{CSSMathNegate}} or {{CSSMathInvert}}:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean CSSMathProduct? Cause that is dealt with in the above step. Or do you mean the case where values in |thisAndValues| are not all of the same type? If the latter in that case we should return a false right?

@tabatkins tabatkins dismissed their stale review June 30, 2017 20:39

Gonna go ahead and merge and fix things up myself.

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.

3 participants