Test-If: Difference between revisions

From FSDeveloper Wiki
Jump to navigationJump to search
m (New page: {{Test-If | state = Blue }})
 
mNo edit summary
 
(24 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{:Ambox-Wiki-Editors}}
Hi Folks
Could we please install the ParserFunctions MediaWiki extension ?
See - http://meta.wikimedia.org/wiki/ParserFunctions
Many thanks
ATB
Paul
Ignore the rest of this page
as it won't work without ParserFunctions
Some results from parser function parameters:
== If Tests ==
If tests look to be working ok.
=== ifeq ===
<pre>{{#ifeq:{{lc:AbC}}|abc|yes}}  should evaluate to 'yes' </pre>
Result = '''{{#ifeq:{{lc:AbC}}|abc|yes}}'''
<pre>{{#ifeq:banana|abc|true|false}}  should evaluate to 'false' </pre>
Result = '''{{#ifeq:banana|abc|true|false}}'''
<pre>{{#ifeq:yellow|yellow|true|false}}  should evaluate to 'true' </pre>
Result = '''{{#ifeq:yellow|yellow|true|false}}'''
=== ifexpr ===
<pre>{{#ifexpr: 10 > 9 | yes | no}}  should evaluate to 'yes' </pre>
Result = '''{{#ifexpr: 10 > 9|yes|no}}'''.
<pre>{{#ifexpr: 9 > 10 | yes | no}}  should evaluate to 'no' </pre>
Result = '''{{#ifexpr: 9 > 10|yes|no}}'''.
{| class="prettytable"
! Operator
! Operation
! Example
! Result
|-
| rowspan="2" colspan="2" align="center"| ''none''
| {{ft|#expr|123456789012345}}
| {{#expr:123456789012345}}
|-
| {{ft|#expr|0.000001}}
| {{#expr:0.000001}}
|-
!colspan="4"| Arithmetic
|-
! +
| Unary positive sign
| {{ft|#expr|+30 * +7}}
| {{#expr:+30 * +7}}
|-
!-
| Unary negative sign
| {{ft|#expr|-30 * -7}}
| {{#expr:-30 * -7}}
|-
! *
| Multiplication
| {{ft|#expr|30 * 7}}
| {{#expr:30 * 7}}
|-
! /<br />div
| Division
| {{ft|#expr|30 / 7}}<br />{{ft|#expr|30 div 7}}
| {{#expr:30 / 7}}<br />{{#expr:30 div 7}}
|-
! <tt>+</tt>
| Addition
| {{ft|#expr|30 + 7}}
| {{#expr:30 + 7}}
|-
! <tt>-</tt>
| Subtraction
| {{ft|#expr|30 - 7}}
| {{#expr:30 - 7}}
|-
!colspan="4"| Logic
|-
! not
| Unary NOT<br />logical NOT
| {{ft|#expr|not 0 * 7}}<br />{{ft|#expr|not 30 + 7}}
| {{#expr: not 0 * 7}}<br />{{#expr:not 30+7}}
|-
! and
| Logical AND
|
{{ft|#expr|4 &lt; 5 and 4 mod 2}}
|{{#expr: 4<5 and 4 mod 2}}
|-
! or
| Logical OR
|
{{ft|#expr|4 &lt; 5 or 4 mod 2}}
|{{#expr: 4<5 or 4 mod 2}}
|-
!colspan="4"| Comparison
|-
! =
| Equality (numerical & logical)
| {{ft|#expr|<nowiki>30 = 7</nowiki>}}
| {{#expr:30 = 7}}
|-
! &lt;&gt;<br />!=
| Inequality, logical exclusive or
| {{ft|#expr|30 &lt;&gt; 7}}<br />{{ft|#expr|<nowiki>1 != 0</nowiki>}}
| {{#expr:30 <> 7}}<br />{{#expr:1 != 0}}
|-
! &lt;
| Less than
|
{{ft|#expr|30 &lt; 7}}
|{{#expr: 30 < 7}}
|-
! &gt;
| Greater than
|
{{ft|#expr|30 &gt; 7}}
|{{#expr: 30 > 7}}
|-
! &lt;=
| Less than or equal to
|
{{ft|#expr|<nowiki>30 &lt;= 7</nowiki>}}
|{{#expr: 30 <= 7}}
|-
! &gt;=
| Greater than or equal to
|
{{ft|#expr|<nowiki>30 &gt;= 7</nowiki>}}
|{{#expr: 30 >= 7}}
|-
!colspan="4"| Other
|-
! ( )
| Grouping operators
| {{ft|#expr|(30 + 7) * 7 }}
| {{#expr:(30 + 7) * 7 }}
|-
! mod
| "Modulo" truncates the numbers to whole numbers, divides the left number by the right, and returns the remainder that could not be divided.<br />Note: ''div'' and ''mod'' are different from all programming languages.
| {{ft|#expr|30 mod 7}}<br />{{ft|#expr|-8 mod -3}}<br />{{ft|#expr|8 mod 2.7}}<br />
| {{#expr:30 mod 7}}<br />{{#expr:-8 mod -3}}<br />{{#expr:8 mod 2.7}}<br />
|-
! round
| Rounds off the number on the left to the power of 1/10 given on the right.
| {{ft|#expr|30 / 7 round 4}}<br />{{ft|#expr|30 / 7 round 1}}<br />{{ft|#expr|1911 round -2}}<br />{{ft|#expr|-2.5 round 0}}
| {{#expr: 30 / 7 round 4}}<br />{{#expr:30 / 7 round 1}}<br />{{#expr:1911 round -2}}<br />{{#expr:-2.5 round 0}}
|}
== To Investigate ==
May require other template(s). Though AFAIK I don't need these.  ;-)
<pre>{{#len:string}} for string = 123456789 should evaluate to '9' </pre>Result = '''{{#len:123456789}}'''
<pre>{{#pos:string|target|offset}}  should evaluate to '10' </pre>Result = '''{{#pos:blah blah target in string|target|offset}}'''
== Table Row Test ==
I'll need to remove my workaround attempts.
<noinclude>Prefix Data not passed</noinclude>
{{Test-If
{{Test-If
| state = Blue
 
| title = Related
| label = acceptable & valid -
 
|ok = legal
|notok = illegal
 
| class_1 = OKParents
| label_1 = Parents
| members_1 = Father . Mother . Parent
 
| class_2 = NotOkParents
| label_2 = Unsuitable Parent Relationships
| members_2 = Brother . Sister . Sibling
 
| class_3 = OKChildren
| label_3 = Children
| members_3 = Daughter . Son . Child
 
| class_4 = NotOkChildren
| label_4 = Unsuitable Child Relationships
| members_4 = Brother . Sister . Sibling . Peer
 
}}
}}
<noinclude>Suffix Data not passed</noinclude>
[[Category:Wiki-Documentation]]

Latest revision as of 09:13, 1 June 2009

Hi Folks

Could we please install the ParserFunctions MediaWiki extension ? See - http://meta.wikimedia.org/wiki/ParserFunctions

Many thanks ATB Paul

Ignore the rest of this page as it won't work without ParserFunctions


Some results from parser function parameters:

If Tests

If tests look to be working ok.

ifeq

{{#ifeq:{{lc:AbC}}|abc|yes}}  should evaluate to 'yes' 

Result = yes

{{#ifeq:banana|abc|true|false}}  should evaluate to 'false' 

Result = false

{{#ifeq:yellow|yellow|true|false}}  should evaluate to 'true' 

Result = true


ifexpr

{{#ifexpr: 10 > 9 | yes | no}}  should evaluate to 'yes' 

Result = yes.

{{#ifexpr: 9 > 10 | yes | no}}  should evaluate to 'no' 

Result = no.

Operator Operation Example Result
none {{ #expr123456789012345 }} 1.2345678901234E+14
{{ #expr0.000001 }} 1.0E-6
Arithmetic
+ Unary positive sign {{ #expr+30 * +7 }} 210
- Unary negative sign {{ #expr-30 * -7 }} 210
* Multiplication {{ #expr30 * 7 }} 210
/
div
Division {{ #expr30 / 7 }}
{{ #expr30 div 7 }}
4.2857142857143
4.2857142857143
+ Addition {{ #expr30 + 7 }} 37
- Subtraction {{ #expr30 - 7 }} 23
Logic
not Unary NOT
logical NOT
{{ #exprnot 0 * 7 }}
{{ #exprnot 30 + 7 }}
7
7
and Logical AND

{{ #expr4 < 5 and 4 mod 2 }}

0
or Logical OR

{{ #expr4 < 5 or 4 mod 2 }}

1
Comparison
= Equality (numerical & logical) {{ #expr30 = 7 }} 0
<>
!=
Inequality, logical exclusive or {{ #expr30 <> 7 }}
{{ #expr1 != 0 }}
1
1
< Less than

{{ #expr30 < 7 }}

0
> Greater than

{{ #expr30 > 7 }}

1
<= Less than or equal to

{{ #expr30 <= 7 }}

0
>= Greater than or equal to

{{ #expr30 >= 7 }}

1
Other
( ) Grouping operators {{ #expr(30 + 7) * 7  }} 259
mod "Modulo" truncates the numbers to whole numbers, divides the left number by the right, and returns the remainder that could not be divided.
Note: div and mod are different from all programming languages.
{{ #expr30 mod 7 }}
{{ #expr-8 mod -3 }}
{{ #expr8 mod 2.7 }}
2
-2
0
round Rounds off the number on the left to the power of 1/10 given on the right. {{ #expr30 / 7 round 4 }}
{{ #expr30 / 7 round 1 }}
{{ #expr1911 round -2 }}
{{ #expr-2.5 round 0 }}
4.2857
4.3
1900
-3


To Investigate

May require other template(s). Though AFAIK I don't need these.  ;-)

{{#len:string}} for string = 123456789 should evaluate to '9' 

Result = {{#len:123456789}}

{{#pos:string|target|offset}}  should evaluate to '10' 

Result = {{#pos:blah blah target in string|target|offset}}

Table Row Test

I'll need to remove my workaround attempts.

Prefix Data not passed

Suffix Data not passed