about summary refs log tree commit diff stats
path: root/064random.cc
blob: 0180dfaed8cd46b65e0d79e84d705116a5a79579 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
:(before "End Primitive Recipe Declarations")
RANDOM,
:(before "End Primitive Recipe Numbers")
Recipe_number["random"] = RANDOM;
:(before "End Primitive Recipe Implementations")
case RANDOM: {
  // todo: limited range of numbers, might be imperfectly random
  // todo: thread state in extra ingredients and results
  products.resize(1);
  products.at(0).push_back(rand());
  break;
}

:(before "End Primitive Recipe Declarations")
MAKE_RANDOM_NONDETERMINISTIC,
:(before "End Primitive Recipe Numbers")
Recipe_number["make-random-nondeterministic"] = MAKE_RANDOM_NONDETERMINISTIC;
:(before "End Primitive Recipe Implementations")
case MAKE_RANDOM_NONDETERMINISTIC: {
  srand(time(NULL));
  break;
}

:(before "End Primitive Recipe Declarations")
ROUND,
:(before "End Primitive Recipe Numbers")
Recipe_number["round"] = ROUND;
:(before "End Primitive Recipe Implementations")
case ROUND: {
  assert(scalar(ingredients.at(0)));
  products.resize(1);
  products.at(0).push_back(rint(ingredients.at(0).at(0)));
  break;
}

:(scenario round_to_nearest_integer)
recipe main [
  1:number <- round 12.2
]
+mem: storing 12 in location 1

:(before "End Includes")
#include<math.h>
>("Couldn't set up test: %v\n", err) } t.Run("Parsing Status Query", func(t *testing.T) { data, err := twtxtCache.QueryAllStatuses() if err != nil { t.Errorf("%v\n", err) } out := parseQueryOut(data) conv := strings.Split(string(out), "\n") if !reflect.DeepEqual(data, conv) { t.Errorf("Pre- and Post- parseQueryOut data are inequal:\n%#v\n%#v\n", data, conv) } }) } func Benchmark_parseQueryOut(b *testing.B) { initTestConf() urls := "https://gbmor.dev/twtxt.txt" nick := "gbmor" out, _, err := registry.GetTwtxt(urls) if err != nil { b.Errorf("Couldn't set up test: %v\n", err) } statusmap, err := registry.ParseUserTwtxt(out, nick, urls) if err != nil { b.Errorf("Couldn't set up test: %v\n", err) } err = twtxtCache.AddUser(nick, urls, net.ParseIP("127.0.0.1"), statusmap) if err != nil { b.Errorf("Couldn't set up test: %v\n", err) } data, err := twtxtCache.QueryAllStatuses() if err != nil { b.Errorf("%v\n", err) } b.ResetTimer() for i := 0; i < b.N; i++ { parseQueryOut(data) } }