Skip to content

Commit

Permalink
Types: Question
Browse files Browse the repository at this point in the history
  • Loading branch information
mjal committed Jun 27, 2024
1 parent f8ad3c1 commit 40a68a8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/answer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { map2, map3 } from './utils';
import * as Proof from './proof';
import * as NonZeroProof from './nonZeroProof';
import * as Ciphertext from './ciphertext';
import * as Question from './question';

export namespace AnswerH {
export type t = {
Expand Down Expand Up @@ -96,14 +97,14 @@ export namespace Serialized {
export type t = AnswerH.Serialized.t | AnswerNH.Serialized.t | AnswerL.Serialized.t;

export function IsAnswerH(answer: any, question: any) : answer is AnswerH.Serialized.t {
return (question.type === undefined);
return Question.IsQuestionH(question);
}

export function IsAnswerNH(answer: any, question: any) : answer is AnswerNH.Serialized.t {
return (question.type === "NonHomomorphic");
return Question.IsQuestionNH(question);
}

export function IsAnswerL(answer: any, question: any) : answer is AnswerL.Serialized.t {
return (question.type === "Lists");
return Question.IsQuestionL(question);
}
}
45 changes: 45 additions & 0 deletions src/question.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export namespace QuestionH {
export type t = {
answers: Array<string>;
blank?: boolean;
min: number;
max: number;
question: string;
};
}

export namespace QuestionNH {
export type t = {
type: string;
value: {
answers: Array<string>;
question: string;
}
extra?: any;
};
}

export namespace QuestionL {
export type t = {
type: string;
value: {
answers: Array<Array<string>>;
question: string;
}
extra?: any;
};
}

export type t = QuestionH.t | QuestionNH.t | QuestionL.t

export function IsQuestionH(question: any) : question is QuestionH.t {
return (question.type === undefined);
}

export function IsQuestionNH(question: any) : question is QuestionNH.t {
return (question.type === "NonHomomorphic");
}

export function IsQuestionL(question: any) : question is QuestionL.t {
return (question.type === "Lists");
}

0 comments on commit 40a68a8

Please sign in to comment.