Write select_strategy(meta), where meta is a dict, returning one of 'react', 'reflection', 'tot', 'direct'. Rules, in order: if meta['needs_tools'] -> 'react'; elif meta['verifiable'] and meta['difficulty'] == 'hard' -> 'reflection'; elif meta['open_ended'] or meta['branching'] -> 'tot'; else 'direct'. Missing keys are falsy. Standard library only.
from unittest import TestCase
from exercise import select_strategy
class Evaluate(TestCase):
def test_tools_means_react(self):
self.assertEqual(select_strategy({'needs_tools': True}), 'react')
def test_hard_verifiable_means_reflection(self):
self.assertEqual(select_strategy({'verifiable': True, 'difficulty': 'hard'}), 'reflection')
def test_open_ended_means_tot(self):
self.assertEqual(select_strategy({'open_ended': True}), 'tot')
def test_default_is_direct(self):
self.assertEqual(select_strategy({}), 'direct')
def select_strategy(meta):
if meta.get('needs_tools'):
return 'react'
if meta.get('verifiable') and meta.get('difficulty') == 'hard':
return 'reflection'
if meta.get('open_ended') or meta.get('branching'):
return 'tot'
return 'direct'