SlideShare una empresa de Scribd logo
Schema, Validation and
Generative Testing
Laurence Chen
twitter: humorless
https://replware.dev
developer@ LINE
CLOSING THE DISTANCEBringing people, information and services closer together
Agenda
● Use case: schema validation
○ Predicates are constraints, not types.
○ Does Clojure.spec compose?
● Clojure.spec provides uniform error message
○ explain-data
○ Application caller has the right to decide how to format the error.
● Generative Testing
○ Example-based testing v.s. Property-based testing
○ Three common ways to write property-based testing
○ Leverage Clojure.spec to generate input
Dynamic language needs schema validation
Data input
Software system
(1) API
(2) Web UI
(3) ETL reading from
file
Using schema validation to ensure data is
correct.
Predicates are constraints, not types.
Does Clojure.spec compose? (and)
Does Clojure.spec compose? (or)
Clojure.spec provides uniform error message
Data input
Software system
(1) API
(2) Web UI
(3) ETL reading
from file
Validation error message
spec/explain-data
Example
(def input-data
{:name “Peter”
:age 21
:sex :male})
(s/def ::name string?)
(s/def ::age #(< % 18))
(s/def ::sex #{:male :female})
(s/def ::child
(s/keys :req-un [::name ::age ::sex]))
;; -------------------------------------
(s/valid? ::child input-data)
;; => false
(s/explain-data ::child input-data)
;; => Validation failed reason in data form
spec/explain-data in Example
● Library callee only returns the error in data form. (output of spec/explain-
data)
● Application caller has the right to decide how to format the error.
Example-based testing
● The correct F needs to satisify certain input, output condition.
● If for all (input, output) pairs in a known set satisfying output = Fn(input),
then Fn is correct.
(To be tested) function
or component
Input:
Known set of values.
Output:
Known set of values.
Generative Testing (Property-based testing)
● output = F1(input).
● F1 is an existing implementation.
● When we generate a large enough random input set and for all input
satisfying F1(input) = Fn(input), then Fn is equivalent to F1.
Large enough
generated random
input set.
F1
Fn
The output set
is equivalent.
Three common ways to write property-based tests
● Existing implementation
● Inverse function
● Describe the traits of the output
Large enough
generated random
input set.
F1
Fn
The output set
is equivalent.
Leverage Clojure.spec to generate input
Q & A

Más contenido relacionado

La actualidad más candente

White box testing
White box testingWhite box testing
White box testing
Purvi Sankhe
 
Function in c programming
Function in c programmingFunction in c programming
Function in c programming
SayeemAhmed8
 
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
Kamiya Toshihiro
 
Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
Python ppt
Python pptPython ppt
Kotlin generics
Kotlin genericsKotlin generics
Kotlin generics
Wei-Shen Lu
 
Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6
Daniyal Mughal
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
Self employed
 
Compiler and symbol table
Compiler and symbol tableCompiler and symbol table
Compiler and symbol table
Sunjid Hasan
 
Type checking
Type checkingType checking
Type checkingrawan_z
 
Method parameters in c#
Method parameters in c#Method parameters in c#
Method parameters in c#
Dr.Neeraj Kumar Pandey
 
Function & Recursion
Function & RecursionFunction & Recursion
Function & Recursion
Meghaj Mallick
 
Parsing
ParsingParsing
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and FunctionsJake Bond
 
C presentation
C presentationC presentation
Mycasestudy
MycasestudyMycasestudy
Mycasestudy
Emmanuel college
 

La actualidad más candente (20)

Ch6
Ch6Ch6
Ch6
 
White box testing
White box testingWhite box testing
White box testing
 
Function in c programming
Function in c programmingFunction in c programming
Function in c programming
 
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Python ppt
Python pptPython ppt
Python ppt
 
Kotlin generics
Kotlin genericsKotlin generics
Kotlin generics
 
Generics
GenericsGenerics
Generics
 
Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6Type checking compiler construction Chapter #6
Type checking compiler construction Chapter #6
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
 
Functions in C
Functions in CFunctions in C
Functions in C
 
Compiler and symbol table
Compiler and symbol tableCompiler and symbol table
Compiler and symbol table
 
Type checking
Type checkingType checking
Type checking
 
Method parameters in c#
Method parameters in c#Method parameters in c#
Method parameters in c#
 
Storage classes
Storage classesStorage classes
Storage classes
 
Function & Recursion
Function & RecursionFunction & Recursion
Function & Recursion
 
Parsing
ParsingParsing
Parsing
 
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
 
C presentation
C presentationC presentation
C presentation
 
Mycasestudy
MycasestudyMycasestudy
Mycasestudy
 

Similar a Schema, validation and generative testing

"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,..."Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...Vladimir Ivanov
 
RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG
Greg.Helton
 
Writing tests
Writing testsWriting tests
Writing tests
Jonathan Fine
 
Software testing: an introduction - 2017
Software testing: an introduction - 2017Software testing: an introduction - 2017
Software testing: an introduction - 2017
XavierDevroey
 
Software testing
Software testingSoftware testing
Software testingBala Ganesh
 
Testing in Python: doctest and unittest
Testing in Python: doctest and unittestTesting in Python: doctest and unittest
Testing in Python: doctest and unittest
Fariz Darari
 
How Not To Be Caught Flat-footed With Unpredictable FME Results
How Not To Be Caught Flat-footed With Unpredictable FME ResultsHow Not To Be Caught Flat-footed With Unpredictable FME Results
How Not To Be Caught Flat-footed With Unpredictable FME Results
Safe Software
 
SherLog: Error Diagnosis by Connecting Clues from Run-time Logs
SherLog: Error Diagnosis by Connecting Clues from Run-time LogsSherLog: Error Diagnosis by Connecting Clues from Run-time Logs
SherLog: Error Diagnosis by Connecting Clues from Run-time Logs
Dacong (Tony) Yan
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)
Amr E. Mohamed
 
Agile Testing Cost Reduction using Pairwise Technique
Agile Testing Cost Reduction using Pairwise Technique Agile Testing Cost Reduction using Pairwise Technique
Agile Testing Cost Reduction using Pairwise Technique
XP Conference India
 
SWE-6 TESTING.pptx
SWE-6 TESTING.pptxSWE-6 TESTING.pptx
SWE-6 TESTING.pptx
prashant821809
 
Software Testing for Data Scientists
Software Testing for Data ScientistsSoftware Testing for Data Scientists
Software Testing for Data Scientists
Ajay Ohri
 
Search-Based Robustness Testing of Data Processing Systems
Search-Based Robustness Testing of Data Processing SystemsSearch-Based Robustness Testing of Data Processing Systems
Search-Based Robustness Testing of Data Processing Systems
Lionel Briand
 
ch11lect1.ppt
ch11lect1.pptch11lect1.ppt
ch11lect1.ppt
ImXaib
 
ch11a23424234242342342342423244lect1.ppt
ch11a23424234242342342342423244lect1.pptch11a23424234242342342342423244lect1.ppt
ch11a23424234242342342342423244lect1.ppt
DorisRois
 
ch11lect1.ppt
ch11lect1.pptch11lect1.ppt
ch11lect1.ppt
NupurMishra34
 
ch11lect1.pptghjgjhjkkljkkkjkjkjljkjhytytgh
ch11lect1.pptghjgjhjkkljkkkjkjkjljkjhytytghch11lect1.pptghjgjhjkkljkkkjkjkjljkjhytytgh
ch11lect1.pptghjgjhjkkljkkkjkjkjljkjhytytgh
ssuser2d043c
 
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
Indu32
 
SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and Junit
Amr E. Mohamed
 

Similar a Schema, validation and generative testing (20)

"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,..."Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
"Formal Verification in Java" by Shura Iline, Vladimir Ivanov @ JEEConf 2013,...
 
RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG RPG Program for Unit Testing RPG
RPG Program for Unit Testing RPG
 
Writing tests
Writing testsWriting tests
Writing tests
 
Software testing: an introduction - 2017
Software testing: an introduction - 2017Software testing: an introduction - 2017
Software testing: an introduction - 2017
 
Software testing
Software testingSoftware testing
Software testing
 
Testing in Python: doctest and unittest
Testing in Python: doctest and unittestTesting in Python: doctest and unittest
Testing in Python: doctest and unittest
 
How Not To Be Caught Flat-footed With Unpredictable FME Results
How Not To Be Caught Flat-footed With Unpredictable FME ResultsHow Not To Be Caught Flat-footed With Unpredictable FME Results
How Not To Be Caught Flat-footed With Unpredictable FME Results
 
SherLog: Error Diagnosis by Connecting Clues from Run-time Logs
SherLog: Error Diagnosis by Connecting Clues from Run-time LogsSherLog: Error Diagnosis by Connecting Clues from Run-time Logs
SherLog: Error Diagnosis by Connecting Clues from Run-time Logs
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)
 
Agile Testing Cost Reduction using Pairwise Technique
Agile Testing Cost Reduction using Pairwise Technique Agile Testing Cost Reduction using Pairwise Technique
Agile Testing Cost Reduction using Pairwise Technique
 
SWE-6 TESTING.pptx
SWE-6 TESTING.pptxSWE-6 TESTING.pptx
SWE-6 TESTING.pptx
 
Software Testing for Data Scientists
Software Testing for Data ScientistsSoftware Testing for Data Scientists
Software Testing for Data Scientists
 
Search-Based Robustness Testing of Data Processing Systems
Search-Based Robustness Testing of Data Processing SystemsSearch-Based Robustness Testing of Data Processing Systems
Search-Based Robustness Testing of Data Processing Systems
 
3.5
3.53.5
3.5
 
ch11lect1.ppt
ch11lect1.pptch11lect1.ppt
ch11lect1.ppt
 
ch11a23424234242342342342423244lect1.ppt
ch11a23424234242342342342423244lect1.pptch11a23424234242342342342423244lect1.ppt
ch11a23424234242342342342423244lect1.ppt
 
ch11lect1.ppt
ch11lect1.pptch11lect1.ppt
ch11lect1.ppt
 
ch11lect1.pptghjgjhjkkljkkkjkjkjljkjhytytgh
ch11lect1.pptghjgjhjkkljkkkjkjkjljkjhytytghch11lect1.pptghjgjhjkkljkkkjkjkjljkjhytytgh
ch11lect1.pptghjgjhjkkljkkkjkjkjljkjhytytgh
 
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
 
SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and Junit
 

Más de Laurence Chen

Create your library
Create your libraryCreate your library
Create your library
Laurence Chen
 
on log messages
on log messageson log messages
on log messages
Laurence Chen
 
The obstacles of developer productivity.pptx
The obstacles of developer productivity.pptxThe obstacles of developer productivity.pptx
The obstacles of developer productivity.pptx
Laurence Chen
 
A simple tool for debug (tap>)
A simple tool for debug (tap>)A simple tool for debug (tap>)
A simple tool for debug (tap>)
Laurence Chen
 
On component interface
On component interfaceOn component interface
On component interface
Laurence Chen
 
The immutable database datomic
The immutable database   datomicThe immutable database   datomic
The immutable database datomic
Laurence Chen
 
The productivity brought by Clojure
The productivity brought by ClojureThe productivity brought by Clojure
The productivity brought by Clojure
Laurence Chen
 

Más de Laurence Chen (7)

Create your library
Create your libraryCreate your library
Create your library
 
on log messages
on log messageson log messages
on log messages
 
The obstacles of developer productivity.pptx
The obstacles of developer productivity.pptxThe obstacles of developer productivity.pptx
The obstacles of developer productivity.pptx
 
A simple tool for debug (tap>)
A simple tool for debug (tap>)A simple tool for debug (tap>)
A simple tool for debug (tap>)
 
On component interface
On component interfaceOn component interface
On component interface
 
The immutable database datomic
The immutable database   datomicThe immutable database   datomic
The immutable database datomic
 
The productivity brought by Clojure
The productivity brought by ClojureThe productivity brought by Clojure
The productivity brought by Clojure
 

Último

Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 

Último (20)

Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 

Schema, validation and generative testing

  • 1. Schema, Validation and Generative Testing Laurence Chen twitter: humorless https://replware.dev developer@ LINE
  • 2. CLOSING THE DISTANCEBringing people, information and services closer together
  • 3. Agenda ● Use case: schema validation ○ Predicates are constraints, not types. ○ Does Clojure.spec compose? ● Clojure.spec provides uniform error message ○ explain-data ○ Application caller has the right to decide how to format the error. ● Generative Testing ○ Example-based testing v.s. Property-based testing ○ Three common ways to write property-based testing ○ Leverage Clojure.spec to generate input
  • 4. Dynamic language needs schema validation Data input Software system (1) API (2) Web UI (3) ETL reading from file Using schema validation to ensure data is correct.
  • 8. Clojure.spec provides uniform error message Data input Software system (1) API (2) Web UI (3) ETL reading from file Validation error message
  • 10. Example (def input-data {:name “Peter” :age 21 :sex :male}) (s/def ::name string?) (s/def ::age #(< % 18)) (s/def ::sex #{:male :female}) (s/def ::child (s/keys :req-un [::name ::age ::sex])) ;; ------------------------------------- (s/valid? ::child input-data) ;; => false (s/explain-data ::child input-data) ;; => Validation failed reason in data form
  • 11. spec/explain-data in Example ● Library callee only returns the error in data form. (output of spec/explain- data) ● Application caller has the right to decide how to format the error.
  • 12. Example-based testing ● The correct F needs to satisify certain input, output condition. ● If for all (input, output) pairs in a known set satisfying output = Fn(input), then Fn is correct. (To be tested) function or component Input: Known set of values. Output: Known set of values.
  • 13. Generative Testing (Property-based testing) ● output = F1(input). ● F1 is an existing implementation. ● When we generate a large enough random input set and for all input satisfying F1(input) = Fn(input), then Fn is equivalent to F1. Large enough generated random input set. F1 Fn The output set is equivalent.
  • 14. Three common ways to write property-based tests ● Existing implementation ● Inverse function ● Describe the traits of the output Large enough generated random input set. F1 Fn The output set is equivalent.
  • 15. Leverage Clojure.spec to generate input
  • 16. Q & A