Created
November 14, 2016 21:00
-
-
Save brianmfear/c6a152ee5cab168f573c037ad1756497 to your computer and use it in GitHub Desktop.
Ternary Lazy Evaluation Demo (salesforce.com Apex Code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest class TernaryLazyEvalTest { | |
static Integer counter = 0; | |
static Boolean flag { get; set { counter++; flag = value; } } | |
static Boolean setTrue() { | |
return flag = true; | |
} | |
static Boolean setFalse() { | |
return flag = false; | |
} | |
@isTest static void unitTest() { | |
Boolean result = Math.random()<0.5?setTrue():setFalse(); | |
// If counter is two, that means both sides of ternary were evaluated | |
System.assertEquals(1, counter); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment