OK. No idea why people would want to do this, BUT, here is a demo of using OPA to run a random quiz. My challenge was as follows: No custom code and use out-of-the-box functionality!
I created this in about 4-5 hours of playing around after I got it though my head that I wanted to prove it could be done.
I put the questions and answers in a rule spreadsheet (of course, this can also be fed by an external table). At the beginning of the interview, I simply tell OPA how many random questions to select, and...
OPA will randomly select and order the desired number of questions from the spreadsheet to be asked randomly in the interview.
OPA will randomize the answers to the questions so you can't cheat.
OPA will score it.
This was more a "prove it can be done" activity than anything I would necessarily recommend. The example is bare-bones, the code is uncommented. I suppose, if I was given a month, I could create an OPA quiz/test system that would blow away anything you could buy commercially. After all, I have the backing of a rules engine...
Architecturally, I am not sure I recommend this, especially for the "new to OPA" crowd. I kinda skirt around Rule Principle #6, but I think it can be argued that this rule is not totally violated. When "random" comes into the picture, the value of rule #6 comes into question.
For people who are curious, how the f**k Fowler got around random functions and specific ordering on the interview screens, well... I used the random number generator I wrote a few years back in OPA, and I played an interview ordering trick that I don't like to share (but in this case, since the ordering will be random regardless, I don't mind sharing the trick.) OPA interviews display entities in the internal order that OPA created the entities. I used that to my advantage for the specific ordering on the interview screen. I cheated.
I had OPA create a bunch of empty entities using a technique of creating iterative entity instances https://documentation.custhelp.com/euf/assets/devdocs/cloud19b/PolicyAutomation/en/Default.htm#Guides/Policy_Modeling_Us…
I KNOW what the order of those empty entities must be and I know how they will be displayed. All I needed to do was transfer my questions / answers into those empty instances in an ordering of my selection, and TADA - they appear on the screen in that ordering :-)
Ok, that really is cheating. But, even if I can't rely on OPA to always use entity ordering during display, the very fact that I reorder my questions and answers based on a random number generation means that in this one specific use case - who cares? It is random anyway! If future OPA releases change ordering due to internal engine changes, then it will just be even more random... It is a random quiz, after all.
Sooo... I attached my policy model proving a quiz can be done. Someday, I may revisit this post to add really complex quiz and test functionality. I may post something more than 4-5 hours of work and a lot more documentation...
This policy model was created in the latest version of OPA - 19B from May 2019... This model is not for the beginner.
Quiz.zip 122.0 K