anchor.diff:      [?_assertEqual(10, gcd(10, 0)),
        ?_assertEqual(5, gcd(0, 5)),
        ?_assertEqual(5, gcd(10, 5))
  +    ].
  +
  +consolidate_test_() ->
  +    Series = pseudo_series([1,2,1,2,1,2,1,5]),
  +    Expected = pseudo_series([1.5,1.5,1.5,3.0], 20),
  +    [?_assertEqual(Expected, consolidate(Series, 2)),
  +     ?_assertEqual(pseudo_series([1.5], 30), consolidate(pseudo_series([1, null, 2]), 3)),
  +     ?_assertEqual(pseudo_series([1.5, 1.0], 30), consolidate(pseudo_series([1, null, 2, null, null, 1]), 3)),
  +     ?_assertEqual(pseudo_series([], 20), consolidate(pseudo_series([]), 2))
       ].
   
   percentile_test_() ->
  
positive.code:     #series{target=Target}.
  
  pseudo_values(Series) ->
      {Lst, _Idx} = lists:foldr(fun(V, {Acc, Idx}) -> {[{Idx, V} | Acc], Idx + 10} end, {[], 100}, Series),
      Lst.
  
  pseudo_series(Values) ->
      Target = <<"target">>,
      [#series{target=Target,values=pseudo_values(Values)}].
  
  derivative_test_() ->
      [?_assertEqual([], derivative([])),
  
negative.code:     end.
  
  
  consolidate(Series, ValuesPP) ->
      consolidate(Series, ValuesPP, fun safe_average/1).
  
  consolidate(Series, ValuesPP, _Func) when ValuesPP =< 1 -> Series;
  consolidate(Series, ValuesPP, Func) ->
      Values = consolidate_values(Series#series.values, ValuesPP, Func),
      Step = Series#series.step * ValuesPP,
      Series#series{values=Values,step=Step}.
  
  
  consolidate_values([], _ValuesPP, _Func) -> [];
  consolidate_values([{TS0, Val0}=Hd | Tl], ValuesPP, Func) ->
      {Vs, Cs, TS, _} = lists:foldl(fun({TS, null}, {Result, ConsVs, TS0, Cnt}) when Cnt == ValuesPP->
                                            {[{TS0, Func(ConsVs)} | Result], [], TS, 1};
                                       ({TS, Val}, {Result, ConsVs, TS0, Cnt}) when Cnt == ValuesPP ->
                                            {[{TS0, Func(ConsVs)} | Result], [Val], TS, 1};
                                       ({_TS, null}, {Result, ConsVs, TS, Cnt}) ->
                                            {Result, ConsVs, TS, Cnt+1};
                                       ({_TS, Val}, {Result, ConsVs, TS, Cnt}) ->
                                            {Result, [Val | ConsVs], TS, Cnt+1}
                                    end, {[], [Val0], TS0, 1}, Tl),
      case Cs of
          [] -> lists:reverse(Vs);
          _ -> lists:reverse([{TS, Func(Cs)} | Vs])
      end.
  
  
  safe_minimum([]) -> null;
  safe_minimum(Values) ->
      safe_minimum(Values, null).
  