SlideShare a Scribd company 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

More Related Content

What's hot

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
 

What's hot (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 to 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 to 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
 

More from 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
 

More from 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
 

Recently uploaded

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
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
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 

Recently uploaded (20)

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
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
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 

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