FreeMarker: Numeric Operations Test

A simple test follows:

${message}

Start with the increment operator:

<#assign a1 = 0>

a1 = ${a1}

<#assign a1 = a1 + 1>

a1 = ${a1}

<#assign a1 = a1 + 1>

a1 = ${a1}

Now the decrement operator:

<#assign a2 = 5>

a2 = ${a2}

<#assign a2 = a2 - 1>

a2 = ${a2}

<#assign a2 = a2 - 1>

a2 = ${a2}

<#assign a2 = a2 - 1>

a2 = ${a2}

<#assign a2 = a2 - 1>

a2 = ${a2}

<#assign a2 = a2 - 1>

a2 = ${a2}

<#assign a2 = a2 - 1>

a2 = ${a2}

<#assign a2 = a2 - 1>

Now the add operator:

<#assign op1 = 5> <#assign op2 = 3> <#assign op3 = op1 + op2>

op1 = ${op1}, op2 = ${op2}, op3 = ${op3}

<#assign op3 = op3 + op2>

op3 = ${op3}

And the subtract operator:

<#assign op3 = op1 - op2 >

op1 = ${op1}, op2 = ${op2}, op3 = ${op3}

<#assign op3 = op3 - op2 >

op3 = ${op3}

The comparison operators:

<#assign list1 = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]> <#foreach item in list1>

Item is: ${item}

<#if item lt 5>

Item is less than five.

<#if item <= 7>

Item is less than or equals to seven.

<#if item gt 2>

Item is greater than two.

<#if (item >= 10)>

Item is greater than or equal to ten.

<#-- Signum-based optimization test, all 9 permutations: --> <#-- 1 --> <@assert test= !(0 != 0) /> <@assert test= (0 == 0) /> <@assert test= !(0 > 0) /> <@assert test= (0 >= 0) /> <@assert test= !(0 < 0) /> <@assert test= (0 <= 0) /> <#-- 2 --> <@assert test= !(3 != 3) /> <@assert test= (3 == 3) /> <@assert test= !(3 > 3) /> <@assert test= (3 >= 3) /> <@assert test= !(3 < 3) /> <@assert test= (3 <= 3) /> <#-- 3 --> <@assert test= !(-3 != -3) /> <@assert test= (-3 == -3) /> <@assert test= !(-3 > -3) /> <@assert test= (-3 >= -3) /> <@assert test= !(-3 < -3) /> <@assert test= (-3 <= -3) /> <#-- 4 --> <@assert test= (3 != 0) /> <@assert test= !(3 == 0) /> <@assert test= (3 > 0) /> <@assert test= (3 >= 0) /> <@assert test= !(3 < 0) /> <@assert test= !(3 <= 0) /> <#-- 5 --> <@assert test= (0 != 3) /> <@assert test= !(0 == 3) /> <@assert test= !(0 > 3) /> <@assert test= !(0 >= 3) /> <@assert test= (0 < 3) /> <@assert test= (0 <= 3) /> <#-- 6 --> <@assert test= (-3 != 0) /> <@assert test= !(-3 == 0) /> <@assert test= !(-3 > 0) /> <@assert test= !(-3 >= 0) /> <@assert test= (-3 < 0) /> <@assert test= (-3 <= 0) /> <#-- 7 --> <@assert test= (0 != -3) /> <@assert test= !(0 == -3) /> <@assert test= (0 > -3) /> <@assert test= (0 >= -3) /> <@assert test= !(0 < -3) /> <@assert test= !(0 <= -3) /> <#-- 8 --> <@assert test= (-3 != 3) /> <@assert test= !(-3 == 3) /> <@assert test= !(-3 > 3) /> <@assert test= !(-3 >= 3) /> <@assert test= (-3 < 3) /> <@assert test= (-3 <= 3) /> <#-- 9 --> <@assert test= (3 != -3) /> <@assert test= !(3 == -3) /> <@assert test= (3 > -3) /> <@assert test= (3 >= -3) /> <@assert test= !(3 < -3) /> <@assert test= !(3 <= -3) /> <#-- Again, now on runtime: --> <#assign m3 = -3> <#assign p3 = 3> <#assign z = 0> <#-- 1 --> <@assert test= !(z != z) /> <@assert test= (z == z) /> <@assert test= !(z > z) /> <@assert test= (z >= z) /> <@assert test= !(z < z) /> <@assert test= (z <= z) /> <#-- 2 --> <@assert test= !(p3 != p3) /> <@assert test= (p3 == p3) /> <@assert test= !(p3 > p3) /> <@assert test= (p3 >= p3) /> <@assert test= !(p3 < p3) /> <@assert test= (p3 <= p3) /> <#-- 3 --> <@assert test= !(m3 != m3) /> <@assert test= (m3 == m3) /> <@assert test= !(m3 > m3) /> <@assert test= (m3 >= m3) /> <@assert test= !(m3 < m3) /> <@assert test= (m3 <= m3) /> <#-- 4 --> <@assert test= (p3 != z) /> <@assert test= !(p3 == z) /> <@assert test= (p3 > z) /> <@assert test= (p3 >= z) /> <@assert test= !(p3 < z) /> <@assert test= !(p3 <= z) /> <#-- 5 --> <@assert test= (z != p3) /> <@assert test= !(z == p3) /> <@assert test= !(z > p3) /> <@assert test= !(z >= p3) /> <@assert test= (z < p3) /> <@assert test= (z <= p3) /> <#-- 6 --> <@assert test= (m3 != z) /> <@assert test= !(m3 == z) /> <@assert test= !(m3 > z) /> <@assert test= !(m3 >= z) /> <@assert test= (m3 < z) /> <@assert test= (m3 <= z) /> <#-- 7 --> <@assert test= (z != m3) /> <@assert test= !(z == m3) /> <@assert test= (z > m3) /> <@assert test= (z >= m3) /> <@assert test= !(z < m3) /> <@assert test= !(z <= m3) /> <#-- 8 --> <@assert test= (m3 != p3) /> <@assert test= !(m3 == p3) /> <@assert test= !(m3 > p3) /> <@assert test= !(m3 >= p3) /> <@assert test= (m3 < p3) /> <@assert test= (m3 <= p3) /> <#-- 9 --> <@assert test= (p3 != m3) /> <@assert test= !(p3 == m3) /> <@assert test= (p3 > m3) /> <@assert test= (p3 >= m3) /> <@assert test= !(p3 < m3) /> <@assert test= !(p3 <= m3) />