This is the page of testcases for: Template:Val.

Overview మార్చు

The testcases, listed below, are intended to show the working options for Template:Val, and for its experimental variation Template:Val/sandbox (to develop new options). The variety of testcases is intended to be a broad sample of all possible options, so as to better catch any mistakes introduced during updates.

Live testcases for Template:Val మార్చు

Here are some tests to see if {{val}} works correctly:

  • {{val|1}} = 1
  • {{val|1|2}} = 1±2
  • {{val|1|(2)}} = 1(2)
  • {{val|1|2|-3}} = 1+2
    −3
  • {{val|1|e=1}} = 1×101
  • {{val|1|e=-1}} = 1×10−1
  • {{val|1|u=X}} = 1 X
  • {{val|p=Δ |12.34|s=%}} = Δ 12.34%
  • {{val|p=Δ |1245.6789|12345|-12345|e=12345|u=kg|s=%}} = Δ 1245.6789+12345
    −12345
    ×1012345 kg%

Various ways of displaying units with/without links:

  • {{val|1|u=m/s}} = 1 m/s
  • {{val|1|u=m*s-1}} = 1 m*s-1
  • {{val|1|u=m|up=s}} = 1 m/s
  • {{val|1|ul=m/s}} = m/s
  • {{val|1|ul=m*s-1}} = m*s-1
  • {{val|1|ul=m|up=s}} = m/s
  • {{val|1|u=m|upl=s}} = 1 m/s
  • {{val|1|ul=m|upl=s}} = m/s

Tests for grouping digits:

  • {{val|12}} = 12
  • {{val|123}} = 123
  • {{val|1234}} = 1234
  • {{val|12345}} = 12345
  • {{val|123456}} = 123456
  • {{val|1234567}} = 1234567
  • {{val|12345678}} = 12345678
  • {{val|123456789}} = 123456789
  • {{val|1234567890}} = 1234567890
  • {{val|12345678901}} = 12345678901
  • {{val|123456789012}} = 123456789012
  • {{val|1234567890123}} = 1234567890123
  • {{val|12345678901234}} = 12345678901234
  • {{val|123456789012345}} = 123456789012345
  • {{val|1.2}} = 1.2
  • {{val|1.23}} = 1.23
  • {{val|1.234}} = 1.234
  • {{val|1.2345}} = 1.2345
  • {{val|1.23456}} = 1.23456
  • {{val|1.234567}} = 1.234567
  • {{val|1.2345678}} = 1.2345678
  • {{val|1.23456789}} = 1.23456789
  • {{val|1.234567890}} = 1.234567890
  • {{val|1.2345678901}} = 1.2345678901
  • {{val|1.23456789012}} = 1.23456789012
  • {{val|1.234567890123}} = 1.234567890123
  • {{val|1.2345678901234}} = 1.2345678901234
  • {{val|1.23456789012345}} = 1.23456789012345

Formatting large numbers:

  • {{val|12345}} = 12345
  • {{val|12345|12345}} = 12345±12345
  • {{val|12345|(12345)}} = 12345(12345)
  • {{val|12345|12345|-12345}} = 12345+12345
    −12345
  • {{val|12345|e=12345}} = 12345×1012345
  • {{val|12345|e=-12345}} = 12345×10−12345
  • {{val|12345|u=Non-existing unit}} = 12345 Non-existing unit
  • {{val|p=prefix|12345|s=suffix}} = prefix12345suffix

Error messages:

  • {{val}} =
  • {{val|A|B|C}} = Error in {{val}}: parameter 1 is not a valid number.
  • {{val|1|B|C}} = Error in {{val}}: parameter 2 is not a valid number.
  • {{val|1|1|C}} = Error in {{val}}: parameter 3 is not a valid number.
  • {{val|1|1|1}} = 1+1
    −1
  • {{val|1|e=A}} = Error in {{val}}: exponent parameter (e) is not a valid number.
  • {{val|1|up=s}} = 1/s
  • {{val|1|upl=s}} = 1/s
  • {{val|1|u=|up=}} = 1
  • {{val|1|u=m|ul=m}} = Error in {{val}}: unit (u) and unit with link (ul) are both specified, only one is allowed.
  • {{val|1|u=m|up=m|upl=m}} = Error in {{val}}: unit per (up) and unit per with link (upl) are both specified, only one is allowed.

Testcases for /sandbox version మార్చు

The following testcases show how {{val/sandbox}} works:

  • {{val/sandbox|1}} = 1
  • {{val/sandbox|1|2}} = 1±2
  • {{val/sandbox|1|(2)}} = 1(2)
  • {{val/sandbox|1|2|-3}} = 1+2
    3
  • {{val/sandbox|1|e=1}} = 1×101
  • {{val/sandbox|1|e=-1}} = 1×101
  • {{val/sandbox|1|u=X}} = 1 X
  • {{val/sandbox|p=Δ |12.34|s=%}} = Δ 12.34%
  • {{val/sandbox|p=Δ |1245.6789|12345|-12345|e=12345|u=kg|s=%}} = Δ 1245.6789+12345
    12345
    ×1012345
     కి.గ్రా.%

Various ways of displaying units with/without links:

  • {{val/sandbox|1|u=m/s}} = 1 m/s
  • {{val/sandbox|1|u=m*s-1}} = 1 m·s-1
  • {{val/sandbox|1|u=m|up=s}} = 1 m/s
  • {{val/sandbox|1|ul=m/s}} = 1 m/s
  • {{val/sandbox|1|ul=m*s-1}} = 1 m·s-1
  • {{val/sandbox|1|ul=m|up=s}} = 1 m/s
  • {{val/sandbox|1|u=m|upl=s}} = 1 m/s
  • {{val/sandbox|1|ul=m|upl=s}} = 1 m/s

Tests for grouping digits:

  • {{val/sandbox|12}} = 12
  • {{val/sandbox|123}} = 123
  • {{val/sandbox|1234}} = 1234
  • {{val/sandbox|12345}} = 12345
  • {{val/sandbox|123456}} = 123456
  • {{val/sandbox|1234567}} = 1234567
  • {{val/sandbox|12345678}} = 12345678
  • {{val/sandbox|123456789}} = 123456789
  • {{val/sandbox|1234567890}} = 1234567890
  • {{val/sandbox|12345678901}} = 12345678901
  • {{val/sandbox|123456789012}} = 123456789012
  • {{val/sandbox|1234567890123}} = 1234567890123
  • {{val/sandbox|12345678901234}} = 12345678901234
  • {{val/sandbox|123456789012345}} =
    Error in {{val}}: "123456789012345" is invalid number or too much precision to display.
    123456789012345
  • {{val/sandbox|1.2}} = 1.2
  • {{val/sandbox|1.23}} = 1.23
  • {{val/sandbox|1.234}} = 1.234
  • {{val/sandbox|1.2345}} = 1.2345
  • {{val/sandbox|1.23456}} = 1.23456
  • {{val/sandbox|1.234567}} = 1.234567
  • {{val/sandbox|1.2345678}} = 1.2345678
  • {{val/sandbox|1.23456789}} = 1.23456789
  • {{val/sandbox|1.234567890}} = 1.234567890
  • {{val/sandbox|1.2345678901}} = 1.2345678901
  • {{val/sandbox|1.23456789012}} = 1.23456789012
  • {{val/sandbox|1.234567890123}} = 1.234567890123
  • {{val/sandbox|1.2345678901234}} = 1.2345678901234
  • {{val/sandbox|1.23456789012345}} =
    Error in {{val}}: "1.23456789012345" is invalid number or too much precision to display.
    1.23456789012345

Formatting large numbers:

  • {{val/sandbox|12345}} = 12345
  • {{val/sandbox|12345|12345}} = 12345±12345
  • {{val/sandbox|12345|(12345)}} = 12345(12345)
  • {{val/sandbox|12345|12345|-12345}} = 12345+12345
    12345
  • {{val/sandbox|12345|e=12345}} = 12345×1012345
  • {{val/sandbox|12345|e=-12345}} = 12345×1012345
  • {{val/sandbox|12345|u=Non-existing unit}} = 12345 Non-existing unit
  • {{val/sandbox|p=prefix|12345|s=suffix}} = prefix12345suffix

Error messages:

  • {{val/sandbox|A|B|C}} =
    Error in {{val}}: "A" is invalid number or too much precision to display.

    Error in {{val}}: parameter 2 "B" invalid number or too long to display.

    Error in {{val}}: parameter 3 "C" invalid number or too long to display.
    సమాసంలో(Expression) లోపం: గుర్తించలేని పదం "c"A+B
    C
  • {{val/sandbox|1|B|C}} =
    Error in {{val}}: parameter 2 "B" invalid number or too long to display.

    Error in {{val}}: parameter 3 "C" invalid number or too long to display.
    సమాసంలో(Expression) లోపం: గుర్తించలేని పదం "c"1+B
    C
  • {{val/sandbox|1|1|C}} =
    Error in {{val}}: parameter 3 "C" invalid number or too long to display.
    సమాసంలో(Expression) లోపం: గుర్తించలేని పదం "c"1+1
    C
  • {{val/sandbox|1|1|1}} =
    Error in {{val}}: parameter 3 "1" is not negative.
    1+1
    1
  • {{val/sandbox|1|e=A}} =
    Error in {{val}}: exponent (e=A) not a valid number.
    1×10A
  • {{val/sandbox|1|up=s}} =
    Error in {{val}}: unit (u or ul) is not specified but units-per (up or upl) is.
    1/s
  • {{val/sandbox|1|upl=s}} =
    Error in {{val}}: unit (u or ul) is not specified but units-per (up or upl) is.
    1/s
  • {{val/sandbox|1|u=m|ul=m}} =
    Error in {{val}}: unit (u) and units with link (ul) are both specified, only one is allowed.
    1 m m
  • {{val/sandbox|1|u=m|up=m|upl=m}} =
    Error in {{val}}: unit (u or ul) is not specified but units-per (up or upl) is.

    Error in {{val}}: unit per (up) and units per with link (upl) are both specified, only one is allowed.
    1 m/m/m

Multiple error messages మార్చు

10-Dec-2010: The Template:Val has been performing too many nested if-else-if-else checks on parameters, and has been nested over 20 deep (of the tiny 40-level "Expansion depth limit" in MediaWiki 1.6), before Val processes all decimal digits, nesting 1 level deeper for each digit after 4. This nesting is reduced by checking each validation of parameters as non-nested simple if-then logic (not if-else logic). By contrast, Template:Gaps nests only 2 levels deep (for {gaps|0.123|456|789|u=m} → 0.123456789 m or such). During 2008-2010, the MediaWiki 1.6 software has been using a 40-nest limit to stop "runaway" formatting of pages, when 60 (or 200) levels would be more practical (and stop any looping templates soon enough).

Meawhile, by changing the if-else validation checks to non-nested if-then logic, all error conditions are reported as a sequence of messages, and then the output will still be attempted. However, that is a good tactic because if 2 parameters are wrong, then getting a message for each of them is better (at one time), and then seeing a partial result can help to spot which instance of {Val} has those invalid parameters. Template {Val} had been reporting 1 error and stopping:

  • For {val|0.1234S6|0.L} using 5=S, 1=L gives: Error in {{val}}: parameter 1 is not a valid number.

With the internal nesting reduced, then Val also reports "0.L" as an invalid number.

  • For {val/sandbox|0.1234S6|0.L} using "S" as 5, "L" as 1, gives:
    Error in {{val}}: "0.1234S6" is invalid number or too much precision to display.

    Error in {{val}}: parameter 2 "0.L " invalid number or too long to display.
    Lua error in మాడ్యూల్:Gapnum at line 16: Unable to convert "0.1234S6" to a number.0.L

These results were confirmed using the sandbox variation of Val to show the proposed changes. -Wikid77 (talk) 21:00, 10 December 2010 (UTC)

Using multi-nested templates మార్చు

10-Dec-2010: The Template:Val/sandbox variation was used to develop non-nested validation of parameters. It continues to show messages for each invalid parameter, then always attempts the output, rather than nest the logic when checking for errors, else nest for further processing.

The problems with nesting beyond the tiny 40-level limit (in MediaWiki 1.6 during 2009-2010), which restricts the nesting of templates and if-else logic, is shown in the following examples.

* Nest 27 deep & try {Val/sandbox|9888.12345}: <!--
-->{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x
|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x
|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x|{{1x
|→ {{Val/sandbox|9888.12345}}
}}}} }}}} }}}} }}}} }}}}  }}}} }}}} }}}} }}}} }}}}
}}}} }}}} }}}} }}
  • Nest 27 deep & try {Val/sandbox|9888.12345}: → 9888.12345


  • Nest 20 deep & try {Val|9888.12345}: → 9888.12345
  • Nest 16 deep & try {Val|9888.123456789}: → 9888.123456789

Because {Val} had been coded with nested if-else-if-else-if-else, to check for 8 error conditions, it could not run within other templates nested to 20 deep, during 2009-2010, but the sandbox version could run even when nested 27 deep. When Val processes the decimal digits, it nests 1 level deeper for each decimal digit after 4 (beyond 0.0001). -రమేష్ రామయ్య చర్చ 21:24, 22 ఫిబ్రవరి 2012 (UTC)

"https://te.wikipedia.org/w/index.php?title=మూస:Val/test&oldid=698562" నుండి వెలికితీశారు