Commit 2dcb1e5d authored by Stephane Glondu's avatar Stephane Glondu

Rename modules Question_{std,open} to Question_{h,nh}

parent 7a732c1c
Pipeline #91674 passed with stages
in 26 minutes and 48 seconds
......@@ -22,8 +22,8 @@
open Signatures_core
type question =
| Standard of Question_std_t.question
| Open of Question_open_t.question
| Standard of Question_h_t.question
| Open of Question_nh_t.question
let read_question l b =
let x = Yojson.Safe.read_json l b in
......@@ -31,11 +31,11 @@ let read_question l b =
| `Assoc o ->
(match List.assoc_opt "type" o with
| None ->
Standard (Question_std_j.question_of_string (Yojson.Safe.to_string x))
Standard (Question_h_j.question_of_string (Yojson.Safe.to_string x))
| Some (`String "open") ->
(match List.assoc_opt "value" o with
| None -> failwith "Question.read_question: value is missing"
| Some v -> Open (Question_open_j.question_of_string (Yojson.Safe.to_string v))
| Some v -> Open (Question_nh_j.question_of_string (Yojson.Safe.to_string v))
)
| Some _ ->
failwith "Question.read_question: unexpected type"
......@@ -43,18 +43,18 @@ let read_question l b =
| _ -> failwith "Question.read_question: unexpected JSON value"
let write_question b = function
| Standard q -> Question_std_j.write_question b q
| Standard q -> Question_h_j.write_question b q
| Open q ->
let o = [
"type", `String "open";
"value", Yojson.Safe.from_string (Question_open_j.string_of_question q);
"value", Yojson.Safe.from_string (Question_nh_j.string_of_question q);
]
in
Yojson.Safe.write_json b (`Assoc o)
let erase_question = function
| Standard q ->
let open Question_std_t in
let open Question_h_t in
Standard {
q_answers = Array.map (fun _ -> "") q.q_answers;
q_blank = q.q_blank;
......@@ -63,7 +63,7 @@ let erase_question = function
q_question = "";
}
| Open q ->
let open Question_open_t in
let open Question_nh_t in
Open {
q_answers = Array.map (fun _ -> "") q.q_answers;
q_question = "";
......@@ -72,21 +72,21 @@ let erase_question = function
module Make (M : RANDOM) (G : GROUP) = struct
let ( >>= ) = M.bind
module QStandard = Question_std.Make (M) (G)
module QOpen = Question_open.Make (M) (G)
module QStandard = Question_h.Make (M) (G)
module QOpen = Question_nh.Make (M) (G)
let create_answer q ~public_key ~prefix m =
match q with
| Standard q ->
QStandard.create_answer q ~public_key ~prefix m >>= fun answer ->
answer
|> Question_std_j.string_of_answer G.write
|> Question_h_j.string_of_answer G.write
|> Yojson.Safe.from_string
|> M.return
| Open q ->
QOpen.create_answer q ~public_key ~prefix m >>= fun answer ->
answer
|> Question_open_j.string_of_answer G.write
|> Question_nh_j.string_of_answer G.write
|> Yojson.Safe.from_string
|> M.return
......@@ -95,12 +95,12 @@ module Make (M : RANDOM) (G : GROUP) = struct
| Standard q ->
a
|> Yojson.Safe.to_string
|> Question_std_j.answer_of_string G.read
|> Question_h_j.answer_of_string G.read
|> QStandard.verify_answer q ~public_key ~prefix
| Open q ->
a
|> Yojson.Safe.to_string
|> Question_open_j.answer_of_string G.read
|> Question_nh_j.answer_of_string G.read
|> QOpen.verify_answer q ~public_key ~prefix
let extract_ciphertexts q a =
......@@ -108,12 +108,12 @@ module Make (M : RANDOM) (G : GROUP) = struct
| Standard q ->
a
|> Yojson.Safe.to_string
|> Question_std_j.answer_of_string G.read
|> Question_h_j.answer_of_string G.read
|> QStandard.extract_ciphertexts q
| Open q ->
a
|> Yojson.Safe.to_string
|> Question_open_j.answer_of_string G.read
|> Question_nh_j.answer_of_string G.read
|> QOpen.extract_ciphertexts q
let process_ciphertexts q e =
......
......@@ -22,8 +22,8 @@
open Signatures_core
type question =
| Standard of Question_std_t.question
| Open of Question_open_t.question
| Standard of Question_h_t.question
| Open of Question_nh_t.question
val read_question : Yojson.Safe.lexer_state -> Lexing.lexbuf -> question
val write_question : Bi_outbuf.t -> question -> unit
......
......@@ -24,7 +24,7 @@ open Common
open Signatures_core
open Serializable_builtin_t
open Serializable_core_t
open Question_std_t
open Question_h_t
(** Helper functions *)
......
......@@ -20,7 +20,7 @@
(**************************************************************************)
open Signatures_core
open Question_std_t
open Question_h_t
val question_length : question -> int
......
......@@ -23,7 +23,7 @@ open Platform
open Signatures_core
open Serializable_builtin_t
open Serializable_core_t
open Question_open_t
open Question_nh_t
let check_modulo p x = Z.(geq x zero && lt x p)
......@@ -61,7 +61,7 @@ module Make (M : RANDOM) (G : GROUP) = struct
| SAtomic x, SAtomic y ->
let c = G.compare x.alpha y.alpha in
if c = 0 then G.compare x.beta y.beta else c
| _, _ -> invalid_arg "Question_open.compare_ciphertexts"
| _, _ -> invalid_arg "Question_nh.compare_ciphertexts"
let process_ciphertexts _ es =
Array.fast_sort compare_ciphertexts es;
......
......@@ -20,7 +20,7 @@
(**************************************************************************)
open Signatures_core
open Question_open_t
open Question_nh_t
module Make (M : RANDOM) (G : GROUP) : Question_sigs.QUESTION
with type 'a m := 'a M.t
......
......@@ -55,7 +55,7 @@ let progress_step n =
in ()
let appendStdQuestion div num_questions i q answers =
let open Question_std_t in
let open Question_h_t in
let () =
let c = Dom_html.createH2 document in
let t = document##createTextNode (Js.string q.q_question) in
......@@ -139,7 +139,7 @@ let appendStdQuestion div num_questions i q answers =
check_constraints
let appendOpenQuestion div q answers =
let open Question_open_t in
let open Question_nh_t in
let () =
let c = Dom_html.createH2 document in
let t = document##createTextNode (Js.string q.q_question) in
......@@ -204,7 +204,7 @@ let appendOpenQuestion div q answers =
check_constraints
let appendStdSummary e a q =
let open Question_std_t in
let open Question_h_t in
let h = Dom_html.createH3 document in
let t = document##createTextNode (Js.string q.q_question) in
Dom.appendChild h t;
......@@ -231,7 +231,7 @@ let appendStdSummary e a q =
Dom.appendChild e ul
let appendOpenSummary e a q =
let open Question_open_t in
let open Question_nh_t in
let h = Dom_html.createH3 document in
let t = document##createTextNode (Js.string q.q_question) in
Dom.appendChild h t;
......@@ -336,8 +336,8 @@ let addQuestions sk params qs =
Array.to_list qs |>
List.map (fun q ->
match q with
| Question.Standard x -> q, Array.make (Question_std.question_length x) 0
| Question.Open x -> q, Array.make (Array.length x.Question_open_t.q_answers) 0
| Question.Standard x -> q, Array.make (Question_h.question_length x) 0
| Question.Open x -> q, Array.make (Array.length x.Question_nh_t.q_answers) 0
)
in
match qs with
......
......@@ -66,10 +66,10 @@ let extractQuestion q =
failwith "Maximum number of choices must be greater than 0!";
if (q_max > Array.length q_answers) then
failwith "Maximum number of choices is greater than number of choices!";
let open Question_std_t in
let open Question_h_t in
return (Question.Standard {q_question; q_blank; q_min; q_max; q_answers})
| None ->
let open Question_open_t in
let open Question_nh_t in
return (Question.Open {q_question; q_answers})
let extractTemplate () =
......@@ -252,10 +252,10 @@ let createQuestion q =
let question, answers, props =
match q with
| Question.Standard q ->
let open Question_std_t in
let open Question_h_t in
q.q_question, q.q_answers, Some (q.q_blank, q.q_min, q.q_max)
| Question.Open q ->
let open Question_open_t in
let open Question_nh_t in
q.q_question, q.q_answers, None
in
createQuestionDiv question answers props
......@@ -303,7 +303,7 @@ let createTemplate template =
let b = Dom_html.createButton document in
let t = document##createTextNode (Js.string "Add a question") in
let f _ =
let open Question_std_t in
let open Question_h_t in
let x = createQuestion (Question.Standard {q_question=""; q_blank=None; q_min=0; q_max=1; q_answers=[||]}) in
Dom.appendChild h_questions_div x
in
......
......@@ -3,10 +3,10 @@ src/platform/native/Platform
Serializable_builtin_t
Serializable_builtin_j
Serializable_core_j
Question_std_j
Question_std
Question_open_j
Question_open
Question_h_j
Question_h
Question_nh_j
Question_nh
Question
Serializable_j
Common
......
......@@ -429,7 +429,7 @@ let is_group_fixed se =
let default_contact = "Name <user@example.org>"
let default_questions =
let open Question_std_t in
let open Question_h_t in
let question = {
q_answers = [| "Answer 1"; "Answer 2"; "Answer 3" |];
q_blank = None;
......
......@@ -1661,7 +1661,7 @@ let format_question_result l q r =
match q with
| Question.Standard x ->
let r = Shape.to_array r in
let open Question_std_t in
let open Question_h_t in
let answers = Array.to_list x.q_answers in
let answers = match x.q_blank with
| Some true -> L.blank_vote :: answers
......@@ -1685,7 +1685,7 @@ let format_question_result l q r =
answers;
]
| Question.Open x ->
let open Question_open_t in
let open Question_nh_t in
li [
pcdata x.q_question;
pcdata " ";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment