diff options
Diffstat (limited to 'html/071recipe.cc.html')
-rw-r--r-- | html/071recipe.cc.html | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/html/071recipe.cc.html b/html/071recipe.cc.html index 47204f71..56f55901 100644 --- a/html/071recipe.cc.html +++ b/html/071recipe.cc.html @@ -212,22 +212,29 @@ Transform<span class="Delimiter">.</span>push_back<span class="Delimiter">(</spa <span class="Delimiter">}</span> recipe from_reagent<span class="Delimiter">(</span><span class="Normal">const</span> reagent& r<span class="Delimiter">)</span> <span class="Delimiter">{</span> - assert<span class="Delimiter">(</span>!r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom && r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name == <span class="Constant">"recipe"</span><span class="Delimiter">);</span> + assert<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">);</span> recipe result_header<span class="Delimiter">;</span> <span class="Comment">// will contain only ingredients and products, nothing else</span> result_header<span class="Delimiter">.</span>has_header = <span class="Constant">true</span><span class="Delimiter">;</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>name == <span class="Constant">"recipe"</span><span class="Delimiter">);</span> + <span class="Identifier">return</span> result_header<span class="Delimiter">;</span> + <span class="Delimiter">}</span> + assert<span class="Delimiter">(</span>root_type<span class="Delimiter">(</span>r<span class="Delimiter">.</span>type<span class="Delimiter">)-></span>name == <span class="Constant">"recipe"</span><span class="Delimiter">);</span> <span class="Normal">const</span> type_tree* curr = r<span class="Delimiter">.</span>type<span class="Delimiter">-></span>right<span class="Delimiter">;</span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">nada</span><span class="Comment">*/</span><span class="Delimiter">;</span> curr && !curr<span class="Delimiter">-></span>atom<span class="Delimiter">;</span> curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>left<span class="Delimiter">-></span>atom && curr<span class="Delimiter">-></span>left<span class="Delimiter">-></span>name == <span class="Constant">"->"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> curr = curr<span class="Delimiter">-></span>right<span class="Delimiter">;</span> <span class="Comment">// skip delimiter</span> - <span class="Identifier">break</span><span class="Delimiter">;</span> + <span class="Identifier">goto</span> read_products<span class="Delimiter">;</span> <span class="Delimiter">}</span> result_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>next_recipe_reagent<span class="Delimiter">(</span>curr<span class="Delimiter">-></span>left<span class="Delimiter">));</span> - <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">-></span>right && curr<span class="Delimiter">-></span>right<span class="Delimiter">-></span>atom<span class="Delimiter">)</span> <span class="Delimiter">{</span> - result_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>next_recipe_reagent<span class="Delimiter">(</span>curr<span class="Delimiter">-></span>right<span class="Delimiter">));</span> - <span class="Identifier">return</span> result_header<span class="Delimiter">;</span> <span class="Comment">// no products</span> - <span class="Delimiter">}</span> <span class="Delimiter">}</span> - <span class="Normal">for</span> <span class="Delimiter">(;</span> curr && !curr<span class="Delimiter">-></span>atom<span class="Delimiter">;</span> curr=curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> + <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> + assert<span class="Delimiter">(</span>curr<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> + result_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>next_recipe_reagent<span class="Delimiter">(</span>curr<span class="Delimiter">));</span> + <span class="Identifier">return</span> result_header<span class="Delimiter">;</span> <span class="Comment">// no products</span> + <span class="Delimiter">}</span> + <span class="Normal">read_products</span>: + <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">nada</span><span class="Comment">*/</span><span class="Delimiter">;</span> curr && !curr<span class="Delimiter">-></span>atom<span class="Delimiter">;</span> curr=curr<span class="Delimiter">-></span>right<span class="Delimiter">)</span> result_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>next_recipe_reagent<span class="Delimiter">(</span>curr<span class="Delimiter">-></span>left<span class="Delimiter">));</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> assert<span class="Delimiter">(</span>curr<span class="Delimiter">-></span>atom<span class="Delimiter">);</span> @@ -236,8 +243,33 @@ recipe from_reagent<span class="Delimiter">(</span><span class="Normal">const</s <span class="Identifier">return</span> result_header<span class="Delimiter">;</span> <span class="Delimiter">}</span> -<span class="Comment">// todo: unit test: 'recipe number' vs 'recipe -> number'</span> +<span class="Delimiter">:(before "End Unit Tests")</span> +<span class="Normal">void</span> test_from_reagent_atomic<span class="Delimiter">()</span> <span class="Delimiter">{</span> + reagent a<span class="Delimiter">(</span><span class="Constant">"{f: recipe}"</span><span class="Delimiter">);</span> + recipe r_header = from_reagent<span class="Delimiter">(</span>a<span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> + CHECK<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> +<span class="Delimiter">}</span> +<span class="Normal">void</span> test_from_reagent_non_atomic<span class="Delimiter">()</span> <span class="Delimiter">{</span> + reagent a<span class="Delimiter">(</span><span class="Constant">"{f: (recipe number -> number)}"</span><span class="Delimiter">);</span> + recipe r_header = from_reagent<span class="Delimiter">(</span>a<span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> <span class="Constant">1</span><span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>products<span class="Delimiter">),</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span class="Delimiter">}</span> +<span class="Normal">void</span> test_from_reagent_reads_ingredient_at_end<span class="Delimiter">()</span> <span class="Delimiter">{</span> + reagent a<span class="Delimiter">(</span><span class="Constant">"{f: (recipe number number)}"</span><span class="Delimiter">);</span> + recipe r_header = from_reagent<span class="Delimiter">(</span>a<span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> <span class="Constant">2</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> +<span class="Delimiter">}</span> +<span class="Normal">void</span> test_from_reagent_reads_sole_ingredient_at_end<span class="Delimiter">()</span> <span class="Delimiter">{</span> + reagent a<span class="Delimiter">(</span><span class="Constant">"{f: (recipe number)}"</span><span class="Delimiter">);</span> + recipe r_header = from_reagent<span class="Delimiter">(</span>a<span class="Delimiter">);</span> + CHECK_EQ<span class="Delimiter">(</span>SIZE<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>ingredients<span class="Delimiter">),</span> <span class="Constant">1</span><span class="Delimiter">);</span> + CHECK<span class="Delimiter">(</span>r_header<span class="Delimiter">.</span>products<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> +<span class="Delimiter">}</span> +<span class="Delimiter">:(code)</span> reagent next_recipe_reagent<span class="Delimiter">(</span><span class="Normal">const</span> type_tree* curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span>!curr<span class="Delimiter">-></span>left<span class="Delimiter">)</span> <span class="Identifier">return</span> reagent<span class="Delimiter">(</span><span class="Constant">"recipe:"</span>+curr<span class="Delimiter">-></span>name<span class="Delimiter">);</span> reagent result<span class="Delimiter">;</span> |