true
or false
but its return type is not boolean.null
but it's annotated as @NotNull
or its return type is primitive.Example:
/**
* @return true if user is found, false otherwise
*/
User findUser(String name);
Note that false-positives are possible, as this inspection tries to interpret a human language. However, if the inspection reports incorrectly, it's still possible that the description is confusing and should be rewritten.
New in 2022.3


Code Bites
Posts en español
Say Hello
Aug 11, 2020
Kafka JMS Client to Confluent Cloud example
Jun 5, 2020
Avoid adding credit card in heroku to get MongoDB
Jun 4, 2020
Fixing Error found in diagram Picked up _JAVA_OPTIONS -Dawt.useSystemAAFontSettings=gasp
Apr 5, 2017
Fixing Debian UEFI boot manager with Debian Live
Apr 4, 2017
Shrink LVM volume for Windows partition
Older


ned
Is like `grep` but with powerful replace capabilities.
Unlike `sed`, as it isn't restricted to line oriented editing.
More information: home page
- Recursively search starting in the current directory, ignoring case:
ned --ignore-case --recursive '^[dl]og' home page
- Search always showing colored output:
ned --colors '^[dl]og' home page
- Search never showing colored output:
ned --colors=never '^[dl]og' home page
- Search ignoring certain files:
ned --recursive --exclude '*.htm' '^[dl]og' home page
- Simple replace:
ned 'dog' --replace 'cat' home page
- Replace using numbered group references:
ned 'the ([a-z]+) dog and the ([a-z]+) dog' --replace 'the $2 dog and the $1 dog' home page
- Replace changing case:
ned '([a-z]+) dog' --case-replacements --replace '\U$1\E! dog' --stdout home page
- Preview results of a find and replace without updating the target files:
ned '^[sb]ad' --replace 'happy' --stdout home page


Parameter learning¶
Parameter learning is the task to estimate the values of the conditional probability distributions (CPDs). To make sense of the given data, we can start by counting how often each state of the variable occurs. If the variable is dependent on the parents, the counts are done conditionally on the parents states, i.e. for seperately for each parent configuration.
Currently, the library supports Parameter learning for discrete nodes:
Maximum Likelihood Estimation
Bayesian Estimation
Maximum Likelihood Estimation¶
A natural estimate for the CPDs is to simply use the relative frequencies, with which the variable states have occured.
While very straightforward, the ML estimator has the problem of overfitting to the data. If the observed data is not representative for the underlying distribution, ML estimations will be extremly far off. When estimating parameters for Bayesian networks, lack of data is a frequent problem. Even if the total sample size is very large, the fact that state counts are done conditionally for each parents configuration causes immense fragmentation. If a variable has 3 parents that can each take 10 states, then state counts will be done seperately for 10^3 = 1000 parents configurations. This makes MLE very fragile and unstable for learning Bayesian Network parameters. A way to mitigate MLE’s overfitting is Bayesian Parameter Estimation.
Bayesian Parameter Estimation¶
The Bayesian Parameter Estimator starts with already existing prior CPDs, that express our beliefs about the variables before the data was observed. Those “priors” are then updated, using the state counts from the observed data.
One can think of the priors as consisting in pseudo state counts, that are added to the actual counts before normalization. Unless one wants to encode specific beliefs about the distributions of the variables, one commonly chooses uniform priors, i.e. ones that deem all states equiprobable.
A very simple prior is the so-called K2 prior, which simply adds “1” to the count of every single state. A somewhat more sensible choice of prior is BDeu (Bayesian Dirichlet equivalent uniform prior). For BDeu we need to specify an equivalent sample size “N” and then the pseudo-counts are the equivalent of having observed N uniform samples of each variable (and each parent configuration).
Examples Parameter learning¶
Example Parameter learning 1¶
For this example, we will be investigating the sprinkler data set. This is a very simple data set with 4 variables and each variable can contain value [1] or [0]. The question we can ask: What are the parameters for the DAG given a dataset? Note that his data set is already pre-processed and no missing values are present. We need both a directed acycle graph (DAG) and dataset with the same variables. The idea is to link the dataset with the DAG.
Let’s bring in our dataset.
import bnlearn
df = bnlearn.import_example()
df.head()
Cloudy |
Sprinkler |
Rain |
Wet_Grass |
|---|---|---|---|
0 |
1 |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
1 |
1 |
… |
… |
… |
… |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
0 |
1 |
0 |
1 |
1 |
DAG = bnlearn.import_DAG('sprinkler', CPD=False)
print(DAG)
Cloudy |
Sprinkler |
Rain |
Wet_Grass |
|
|---|---|---|---|---|
Cloudy |
False |
True |
True |
False |
Sprinkler |
False |
False |
False |
True |
Rain |
False |
False |
False |
True |
Wet_Grass |
False |
False |
False |
False |
bnlearn.plot(DAG)
Suppose we observed N “cloudy” occurences among a total of “all clouds”, so we might guess that about “50%” of “cloudy” are “sprinkler” or so.
According to MLE, we should fill the CPDs in such a way, that P(data|model) is maximal. This is achieved when using the relative frequencies.
From the bnlearn library, we’ll need the fit
for this exercise:
DAG_update = bnlearn.parameter_learning.fit(DAG, df)
- CPD of Cloudy:
Cloudy(0)
0.494
Cloudy(1)
0.506
- CPD of Sprinkler:
Cloudy
Cloudy(0)
Cloudy(1)
Sprinkler(0)
0.48
0.70
Sprinkler(1)
0.51
0.29
- CPD of Rain:
Cloudy
Cloudy(0)
Cloudy(1)
Rain(0)
0.65
0.33
Rain(1)
0.34
0.66
- CPD of Wet_Grass:
Rain
Rain(0)
Rain(0)
Rain(1)
Rain(1)
Sprinkler
Sprinkler(0)
Sprinkler(1)
Sprinkler(0)
Sprinkler(1)
Wet_Grass(0)
0.75
0.33
0.25
0.37
Wet_Grass(1)
0.24
0.66
0.74
0.62
Great! We have the probabilities! Lets check how much they differ from the truth. In general it can be seen that the estimated values are not very close at every point to the true values. The main reason is because the dataframe only contains 1000 samples.
DAG_true = bnlearn.import_DAG('sprinkler', CPD=True)
- CPD of Cloudy:
Cloudy(0)
0.5
Cloudy(1)
0.5
- CPD of Sprinkler:
Cloudy
Cloudy(0)
Cloudy(1)
Sprinkler(0)
0.5
0.9
Sprinkler(1)
0.5
0.1
- CPD of Rain:
Cloudy
Cloudy(0)
Cloudy(1)
Rain(0)
0.8
0.2
Rain(1)
0.2
0.8
- CPD of Wet_Grass:
Sprinkler
Sprinkler(0)
Sprinkler(0)
Sprinkler(1)
Sprinkler(1)
Rain
Rain(0)
Rain(1)
Rain(0)
Rain(1)
Wet_Grass(0)
1.0
0.1
0.1
0.01
Wet_Grass(1)
0.0
0.9
0.9
0.99
Lets generate more samples and learn again the parameters. You will see that these results are much closer to the true values.
df = bnlearn.sampling(DAG, n=10000)
DAG_update = bnlearn.parameter_learning.fit(DAG, df)
Example Parameter learning 2¶
Lets try out a more complexer model. We need both a directed acycle graph (DAG) and dataset with the same variables. So again, the idea is to link the dataset with the DAG.
Let’s bring in the asia dataset.
import bnlearn
# Load asia data set
DAG = bnlearn.import_DAG('asia')
# Plot
G = bnlearn.plot(DAG)
# Generate samples
df = bnlearn.sampling(DAG, n=10000)
# Learn parameters
DAG_update = bnlearn.parameter_learning.fit(DAG, df)
This DAG is now updated with parameters which is great because it opens many possibilities in terms of inference or you can start sampling any number of samples you desire.
- CPD of asia:
asia(0)
0.055
asia(1)
0.944
- CPD of bronc:
smoke
smoke(0)
smoke(1)
bronc(0)
0.585
0.319
bronc(1)
0.414
0.680
- CPD of dysp:
bronc
bronc(0)
bronc(0)
bronc(1)
bronc(1)
either
either(0)
either(1)
either(0)
either(1)
dysp(0)
0.714
0.787
0.586
0.123
dysp(1)
0.285
0.212
0.413
0.876
- CPD of either:
lung
lung(0)
lung(0)
lung(1)
lung(1)
tub
tub(0)
tub(1)
tub(0)
tub(1)
either(0)
0.507
0.837
0.642
0.012
either(1)
0.492
0.1625
0.357
0.987
- CPD of lung:
smoke
smoke(0)
smoke(1)
lung(0)
0.132
0.0537
lung(1)
0.867
0.9462
- CPD of smoke:
smoke(0)
0.498
smoke(1)
0.501
- CPD of tub:
asia
asia(0)
asia(1)
tub(0)
0.418
0.0336
tub(1)
0.581
0.9663
- CPD of xray:
either
either(0)
either(1)
xray(0)
0.7693
0.070
xray(1)
0.230
0.929


ensemble.load
Load the used variables and members of a saved ensemble
Syntax
Description
Loads a saved ensemble into memory. Only loads the variables and ensemble members being used by the ensemble object. By default, the ensemble object uses all variables and ensemble members saved in the .ens file. Use the “useVariables”, “useMembers”, and “evolving” commands to instead load a subset of the saved variables and ensemble members.
If the ensemble object implements a static ensemble, then the first output is a matrix with one row per state vector element, and one column per ensemble member. The second output is a scalar ensembleMetadata object that holds the metadata for this ensemble.
If the ensemble object implements an evolving ensemble, then the first output is a 3D array. The third dimension holds the different ensembles in the evolving set. The second output is a vector of ensembleMetadata objects, each holding the metadata for a particular ensemble in the evolving set.
Loads specific ensembles in the evolving set. The first output will be a 3D matrix and the length of the third dimension will match the number of requested ensembles. The second output will be a vector with one ensembleMetadata object per requested ensemble. If the input is -1, selects all ensembles in the evolving set.


Restrictions
Types of pricing and/or restrictions on space at any time
Inventory
Total Spaces
Inventory
Total Spaces
Current Map Zoom Level:
Click Parking Feature to get More Information
Study Areas
Park'n'Ride Lots
Priority Development Areas
Transit Priority Areas
Transit Hubs
Ferry Terminals
BART
Caltrain
Amtrak
Light Rail
Please place Map into the print area.
Print in Landscape mode


Manual process
httrack target site snapshots from https://archive.org/web/
and compare them to the latest snapshot
use meld for comparison
Metasploit
Compare archived urls and fresh urls. Fresh urls export from Burp.
enum_wayback
use scanner/http/enum_wayback
set domain <domain>
set outfile <outfile>


HAMLET RATING: 6/10 --> Barely recommendable
For more reviews and movie screensavers, visit http://www.joblo.com/
Regular readers of my reviews should know by now that Shakespeare and I just don't mix. I think that I was one of the few critics in the world who didn't care much for SHAKESPEARE IN LOVE (5.5/10), and I certainly have done my best to stay away from films which feature the traditional dialogue of the Bard. The fact is that I never studied Shakespeare, never read Shakespeare and never understood what the heck Shakespeare was saying half the time, so why bother? With those reservations in mind, I walked into this latest cinematic presentation of one of the big man's most famous writings, and came up with this...
PLOT: The President of the Denmark Corporation is dead. To everyone's surprise, the widow quickly remarries his brother soon thereafter, leaving son Hamlet wondering about the nefarious behind-the-scenes shenanigans of it all. Of course, when the ghost of Hamlet's dad comes to visit him with some more news regarding his untimely demise, it isn't long before everybody and their uncle begin to suspect Hamlet of going mad. Revenge, death and a lot of hip, modern-day gadgets ensue.
CRITIQUE: Decent enough for a film whose dialogue was mostly Greek to me, this movie scores points on style and acting, but ultimately runs too long, features one too many monologues and just completely lost me in the end. Strangely enough, I actually did enjoy this picture early on, with its modern day setting, its hip leading man, and its solid score, but as the film drove on further and further, I soon found myself straining to figure out what the heck was happening. In the end, I just couldn't get by with just the "gist" of the conversations, I really needed to know what these people were babbling about, but unfortunately for me, the dialogue was just a little too "Shakespeare" to decipher. Having said that, the film also seemed to lack the proper character development, especially in the case of Ophelia and Hamlet, whose "romance" I never really bought into.
On the other hand, I did enjoy most all of the performances in the film, especially Bill Murray, an actor who I was extremely skeptical about before seeing the film. In the end, he won me over with a sort of flighty performance of Polonius, delivering his lines with much authenticity, while still being able to inject it all with a little bit of that "Murray" charm. Julia Stiles was also quite charming and nice to look at, despite her character's lack of true involvement in the story, and Ethan Hawke certainly delivered a good rendition of Hamlet, the slick techno-geek with a little bit of a head case. I also liked the whole look and feel of the flick, which was actually shot entirely in New York City, but didn't care much for the pacing of it all. After a strong start, it seemed as though, every now and again, the characters would slow the whole thing down with long conversations with one another, or better yet, inner-monologues with themselves. Now I imagine this sort of thing might work in a play, or certainly in a book, but when you're watching people babble on about something which you barely understand for a minutes on end...well, it gets kinda lame after a while.
Of course, I would definitely recommend this to any true Shakespeare fan, only as to compare it to all the others, and even some non-fans, if you like any of the actors, who truly do shine in this film (yes, even Kyle MacLachlan was pretty good). Most anyone else could certainly miss this film and not worry too much about the impact that it will have on their lives. I liked it better than most of the other stuffy Shakespeare flicks, but in the end, this one just packed in too much of that ol' Bard dialogue, and not enough coherence.
Little Known Facts about this movie and its stars: Diane Venora, who plays the character of Queen Gertrude in this film, once played Ophelia in a made-for-television version of Hamlet in 1990. She also portrayed the character of Gloria Capulet in the 1996 modern-day Shakespeare movie ROMEO AND JULIET. Boy, she really loves that Shakepeare, eh? Actor Dechen Thurman, who play the Bard's comic relief character of Guildenstern in this film, is the brother of actress Uma Thurman, wife of Hamlet in this film, Ethan Hawke. Casey Affleck is credited as being in this film, but other than one shot of him on a television screen, I honestly can't say that I remember him being in any of it. I'm guessing that most of his stuff was left on the cutting room floor?
Review Date: May 30, 2000 Director: Michael Almereyda Writer: Michael Almereyda Producers: Andrew Fierberg and Amy Hobby Actors: Ethan Hawke as Hamlet Kyle MacLachlan as Claudius Bill Murray as Polonius Julia Stiles as Ophelia Genre: Drama Year of Release: 2000 ------------------------------------ JoBlo's Movie Emporium http://www.joblo.com/ ------------------------------------ (c) 2000 Berge Garabedian
The review above was posted to the
rec.arts.movies.reviews newsgroup (de.rec.film.kritiken for German reviews).
The Internet Movie Database accepts no responsibility for the contents of the
review and has no editorial control. Unless stated otherwise, the copyright
belongs to the author.
Please direct comments/criticisms of the review to relevant newsgroups.
Broken URLs inthe reviews are the responsibility of the author.
The formatting of the review is likely to differ from the original due
to ASCII to HTML conversion.
Related links: index of all rec.arts.movies.reviews reviews


DeleteMapElement()
语法
Result = DeleteMapElement(Map() [, Key$])概要
Removes the current element or the element with the given key from the specified map.
参数
Map() The map to use. Key$ (optional) The key for the item to remove. If this is not specified, then the current element of the map is removed.
返回值
Returns the memory address of the new current element of the map. If the map has no current element after the deletion, the result is 0.
备注
After this call, the new current element is the previous element (the one before the deleted element), which is an arbitrary element, as a map isn't sorted. If that element does not exist (in other words, you deleted the first element in the map) then there is no more current element, as it will be before the first element, like after a ResetMap(). If there was only one element in the map when you deleted it then you are left with no current element!
If the optional 'Key$' parameter is specified then there will be no more current element after this call.
示例
NewMap Country.s() Country("US") = "United States" Country("FR") = "France" Country("GE") = "Germany" ; Delete a country DeleteMapElement(Country(), "FR") ForEach Country() Debug Country() Next
参阅
AddMapElement(), ClearMap(), MapSize()
已支持操作系统
所有


Preparation time
less than 30 mins
Cooking time
30 mins to 1 hour
Serves
Serves 4-6
A tagine is perfect for warming you up on a cold night. Making your own ras-el-hanout makes this dish extra special.
For the ras-el-hanout, mix all of the ras-el-hanout ingredients together until well combined. Grind in a spice grinder or coffee grinder to a fine powder. Store in an airtight jar.
For the tagine, heat a terracotta tagine or heavy-based, lidded casserole over a medium to high heat.
Heat the oil in the tagine or casserole, then add the garlic and fry for 3-4 minutes, or until pale golden-brown.
Add the onions and reduce the heat, then cook the onions slowly for 10-12 minutes, or until softened but not coloured.
When the onions have softened, push them to one side of the tagine or casserole, then increase the heat slightly and add the cumin seeds, ras-el-hanout and cayenne pepper to the empty side of the casserole. Fry for 1-2 minutes, or until fragrant, then stir the spices into onion mixture until they coat the onions.
Add the chopped tomatoes and season, to taste, with salt and freshly ground black pepper. Bring the mixture to a simmer, then cook for 1-2 minutes, stirring well.
Add the fish stock or water, then return the mixture to a simmer.
Add the plaice fillets to the tagine or casserole, then spoon over some of the sauce to cover the fish. Cover the tagine or casserole with the lid, then reduce the heat to low and continue to cook for eight minutes, or until the plaice fillets are cooked through.
Meanwhile, for the couscous, place the couscous, olive oil and lemon juice into a bowl. Pour over the boiling water, stir once, then cover the bowl tightly with cling film. Set aside for five minutes, or until the couscous has absorbed all of the water, then fluff the couscous grains with a fork.
Stir the chopped pistachios, pomegranate seeds and coriander into the couscous until well combined, then season, to taste, with salt and freshly ground black pepper.
Just before serving, squeeze the lemon juice over the plaice tagine, then sprinkle over the coriander leaves.
To serve, divide the couscous equally among four to six serving plates. Place one plaice fillet on top of each serving, then spoon over the remaining tagine.


The original manuscript was pretty big – at least 35 by 50 cm when held open. Several people could gather round a manuscript of this size, and all look at it together. However, the text and notation are really small, so you have to be very close to be able to read it.
This fragment contains chants and prayers and readings. It was probably a reference book, kept in a monastery or cathedral library, and referred to when there was some question over the liturgy for the day. It was certainly used in some way because it has been revised. In the margin, there is a new version of the melody on the word “terra”. Some of the notation has been scraped away, and replaced with different notation, in a different handwriting.
On the last page, a prayer has been added, which is in fact part of the Christmas Day Mass in later manuscripts.


OUT OF SIGHT by DeWyNGaLe * * * 1 / 2
George Clooney, Jennifer Lopez, Ving Rhames, and Steve Zhan star in the comedy about a bank robber. George Clooney stars as Jack Foley, a professional bank robber. He has robbed over 200 banks in his time. He has been caught a few times, and he has been sent to jail a few times. One night at the jail, he and a couple of buddies plan an escape from the jail. Ving Rhames plays Buddy, the man who has a car waiting for Jack and the other two escaping with him. Buddy isn't the only one waiting for Jack and company that night. Federal Marshall Karen Sisco, played by Jennifer Lopez, is there ready to make the bust. Jack makes it out of the jail, but the other two are shot dead. Buddy and Jack shove Karen into the trunk of the car to make sure she doesn't make the bust. Jack stays in the trunk with her, and they discuss many things, including life and movies.
At a gas station, they see Glenn, an old pal, played by Steve Zhan. They put Glenn in the car also, so no information gets out. Jack and Buddy step out of the car to discuss the plan on what they are going to do, and while this happens, Karen persuades Glenn to drive away, getting away from Jack and Buddy. Now, Jack and Buddy must find Glenn, and Karen must find Jack and Buddy. Karen asks Jack's ex-wife about where Jack may be, and doesn't find out much information there.
Karen sees Jack around as she looks for him, and doesn't do anything, acts like he isn't there. When they do meet up, they talk, and she doesn't try to arrest him or anything. She discovers that she is in love with the man she has to take to jail. He loves her to, and doesn't want to hurt her.
Karen also has to find Glenn now as well. She remembers him saying he was going to Detroit, so she suspects she might find Glenn, as well as Jack and Buddy there. At a boxing match, she catches Glenn trying to steal a car from the parking lot. She lets him go, because she has better things to do than to make a bust. She learns from Glenn that the plan is to go to Richard Ripley's house, played by Albert Brooks. Ripley has five point two million dollars worth of uncut diamonds, and everyone is after them. Little does Glenn know that Jack, Buddy, and the others they met up with, changed the plan to stealing the diamonds that same night, so Glenn wouldn't tell anyone.
Jack, Buddy, and the others go to Ripley's house to get the uncut diamonds. The maid answers the door, and the four of them bust into the house.  Jack finds the diamonds on his own, and gives them to Buddy to drive off with. The others with Jack assume that Jack and Buddy are trying to rip them off, but they aren't. Snoopy, (one of the others with them), played by Don Cheadle and Jack get in a fight, but Karen ends it by entering the house and shooting Snoopy dead. She doesn't want to hurt Jack, because they are in love. The ending is also surprising and well done.
Out Of Sight is a cheaply made film, but price doesn't mean anything. Out Of Sight is without a doubt one of the best, most original films of 1998. All of the acting was done wonderfully, the plot was developed, and the setting was great and realistic. George Clooney and Jennifer Lopez do outstanding jobs as their characters, and they make you believe that they are real people. Samuel L. Jackson and Michael Keaton also make short cameos in which they do a good job of acting in. I wish that more people would see Out Of Sight, because of how good it was. It was a little confusing at times, but that doesn't make much of a difference when you have such a great film. All in all, Out Of Sight, is definitely out of sight.
The review above was posted to the
rec.arts.movies.reviews newsgroup (de.rec.film.kritiken for German reviews).
The Internet Movie Database accepts no responsibility for the contents of the
review and has no editorial control. Unless stated otherwise, the copyright
belongs to the author.
Please direct comments/criticisms of the review to relevant newsgroups.
Broken URLs inthe reviews are the responsibility of the author.
The formatting of the review is likely to differ from the original due
to ASCII to HTML conversion.
Related links: index of all rec.arts.movies.reviews reviews


IWAI - Photo annotation
Let's Get Started!
Upload your photo and start to addonate
Add cross
😎
😀
😍
😘
❤
Add shape


We recommend using Visual Studio Community Edition as your programming environment. The community edition has the full power of Visual Studio and enables programming in C#, F#, VB and Python. If you're running on Mac or Linux you can also use MonoDevelop or Xamarin Studio.
If you prefer coding locally, you can run LEAN inside Visual Studio. The LEAN installation takes about 5 minutes and allows you to backtest locally and copy-paste your algorithms into QuantConnect.com. Check out the LEAN-Getting Started Tutorial for more information.


Methods
addCandidatesToElection(electionName, voterName)
Adds a voter to an Election
Parameters:
| Name | Type | Description |
|---|---|---|
electionName |
string | the name of the election receiving the voter |
voterName |
string | the unique name of the voter to add |
Returns:
error if an error occurs or the new voter document hence the need of new: true
addCandidateToElection()
Mounts an array of Voter instances given the name of the candidates
castVoteToCandidateInElection()
Casts a vote to a candidate in a given election
Parameters:
| Name | Type | Description |
|---|---|---|
req.body.election |
string | the name of the election receiving the vote |
req.body.voter |
string | the unique name of the voter who will cast the vote |
req.body.candidate |
string | the unique name of the candidate who will receive the vote |
Returns:
error if an error occurs or the updated votechain for that election
changeElectionStatus() → {Obj}
Changes isActive status of an election
Returns:
: new election object if sucessfull, error message otherwise
TODO: add authentication so that only the user that created the election
is able to change it's status
- Type
- Obj
createElection()
initializes an election. Elections are considered active by default.
- Source:
Returns:
JSON document with the election created or error
Encrypt()
credits for the functions below go to @RandyMohan on https://stackoverflow.com/questions/3486465/is-there-a-way-to-encrypt-in-jquery
- Source:
findVoter()
Receives the name of the candidate and returns it's Voter instance
- Source:
getElection()
Retrieves all elections
- Source:
Returns:
error if an error occurs or the a JSON document containing all elections
getElectionByName()
Retrieve election by name
- Source:
getVotechainFromElection()
Gets a chain of votes linked to a given election
Parameters:
| Name | Type | Description |
|---|---|---|
req.body.electionID |
Number | the ID of the given Election |
Returns:
error if an error occur or the votechain instance requested
isElectionActive()
Receives an election name through req.body.electionName and returns whether it is active or not
Parameters:
| Name | Type | Description |
|---|---|---|
req.body.electionName |
String | the name of given Election |
Returns:
true if election is active, false otherwise


At Facebook, we use Jest to test React applications.
If you are just getting started with React, we recommend using
Create React App. It is ready to use and
ships with Jest! You will only need to add react-test-renderer
for
rendering snapshots.
Run
If you have an existing application you’ll need to install a few packages
to make everything work well together. We are using the
babel-jest
package and the react
babel preset to
transform our code inside of the test environment. Also see
using babel.
Run
Your package.json
should look something like this (where
<current-version>
is the actual latest version number
for the package). Please add the scripts and jest configuration entries:
// package.json
"dependencies": {
"react": "<current-version>",
"react-dom": "<current-version>"
},
"devDependencies": {
"babel-jest": "<current-version>",
"babel-preset-env": "<current-version>",
"babel-preset-react": "<current-version>",
"jest": "<current-version>",
"react-test-renderer": "<current-version>"
},
"scripts": {
"test": "jest"
}
And you’re good to go!
Let’s create a snapshot test for a Link component that renders hyperlinks:
// Link.react.js
import React from 'react';
const STATUS = {
HOVERED: 'hovered',
NORMAL: 'normal',
};
export default class Link extends React.Component {
constructor(props) {
super(props);
this._onMouseEnter = this._onMouseEnter.bind(this);
this._onMouseLeave = this._onMouseLeave.bind(this);
this.state = {
class: STATUS.NORMAL,
};
}
_onMouseEnter() {
this.setState({class: STATUS.HOVERED});
}
_onMouseLeave() {
this.setState({class: STATUS.NORMAL});
}
render() {
return (

{this.props.children}

);
}
}
Now let’s use React’s test renderer and Jest’s snapshot feature to interact with the component and capture the rendered output and create a snapshot file:
// Link.react.test.js
import React from 'react';
import Link from '../Link.react';
import renderer from 'react-test-renderer';
test('Link changes the class when hovered', () => {
const component = renderer.create(
<Link page="http://www.facebook.com">Facebook</Link>,
);
let tree = component.toJSON();
expect(tree).toMatchSnapshot();
// manually trigger the callback
tree.props.onMouseEnter();
// re-rendering
tree = component.toJSON();
expect(tree).toMatchSnapshot();
// manually trigger the callback
tree.props.onMouseLeave();
// re-rendering
tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
When you run yarn test
or jest
, this will
produce an output file like this:
// __tests__/__snapshots__/Link.react.test.js.snap
exports[`Link changes the class when hovered 1`] = `

Facebook

`;
exports[`Link changes the class when hovered 2`] = `

Facebook

`;
exports[`Link changes the class when hovered 3`] = `

Facebook

`;
The next time you run the tests, the rendered output will be compared to
the previously created snapshot. The snapshot should be committed along
code changes. When a snapshot test fails, you need to inspect whether it
is an intended or unintended change. If the change is expected you can
invoke Jest with jest -u
to overwrite the existing snapshot.
The code for this example is available at examples/snapshot.
There’s a caveat around snapshot testing when using Enzyme and React 16+. If you mock out a module using the following style:
Then you will see warnings in the console:
Warning: <SomeComponent /> is using uppercase HTML. Always use lowercase HTML tags in React.
# Or:
Warning: The tag <SomeComponent> is unrecognized in this browser. If you meant to render a React component, start its name with an uppercase letter.
React 16 triggers these warnings due to how it checks element types, and the mocked module fails these checks. Your options are:
Render as text. This way you won’t see the props passed to the mock component in the snapshot, but it’s straightforward:
Render as a custom element. DOM “custom elements” aren’t checked for anything and shouldn’t fire warnings. They are lowercase and have a dash in the name.
react-test-renderer
. The test renderer doesn’t care
about element types and will happily accept
e.g. SomeComponent
. You could check snapshots using the
test renderer, and check component behavior separately using Enzyme.
Disable warnings all together (should be done in your jest setup file):
This shouldn’t normally be your option of choice as useful warnings could be lost. However, in some cases, for example when testing react-native’s components we are rendering react-native tags into the DOM and many warnings are irrelevant. Another option is to swizzling console.warn and supress specific warnings.
If you’d like to assert, and manipulate your rendered components you can use Enzyme or React’s TestUtils. We use Enzyme for this example.
You have to run yarn add --dev enzyme
to use Enzyme. If you
are using a React version below 15.5.0, you will also need to install
react-addons-test-utils
.
Let’s implement a simple checkbox which swaps between two labels:
// CheckboxWithLabel.js
import React from 'react';
export default class CheckboxWithLabel extends React.Component {
constructor(props) {
super(props);
this.state = {isChecked: false};
// bind manually because React class components don't auto-bind
// http://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html#autobinding
this.onChange = this.onChange.bind(this);
}
onChange() {
this.setState({isChecked: !this.state.isChecked});
}
render() {
return (

<input
type="checkbox"
checked={this.state.isChecked}
onChange={this.onChange}
/>
{this.state.isChecked ? this.props.labelOn : this.props.labelOff}

);
}
}
We use Enzyme’s shallow renderer in this example.
// __tests__/CheckboxWithLabel-test.js
import React from 'react';
import {shallow} from 'enzyme';
import CheckboxWithLabel from '../CheckboxWithLabel';
test('CheckboxWithLabel changes the text after click', () => {
// Render a checkbox with label in the document
const checkbox = shallow(<CheckboxWithLabel labelOn="On" labelOff="Off" />);
expect(checkbox.text()).toEqual('Off');
checkbox.find('input').simulate('change');
expect(checkbox.text()).toEqual('On');
});
The code for this example is available at examples/enzyme.
If you need more advanced functionality, you can also build your own transformer. Instead of using babel-jest, here is an example of using babel:
// custom-transformer.js
'use strict';
const babel = require('babel-core');
const jestPreset = require('babel-preset-jest');
module.exports = {
process(src, filename) {
if (babel.util.canCompile(filename)) {
return babel.transform(src, {
filename,
presets: [jestPreset],
});
}
return src;
},
};
Don’t forget to install the babel-core
and
babel-preset-jest
packages for this example to work.
To make this work with Jest you need to update your Jest configuration
with this:
"transform": {"\\.js$": "path/to/custom-transformer.js"}
.
If you’d like to build a transformer with babel support, you can also use babel-jest to compose one and pass in your custom configuration options:


Simple access to helpful tools: it's what you want, and it's what we have. So, we've curated a page of links to tools & resources. Just for you.
Found what you want? Great! Looking for more? No problem. Simply use the navigation dropdown menu at the top of any screen to explore other site content.


Pugna Admin
Register
Full name
Email
Password
Password confirmation
I agree the
terms and conditions
Register
Cancel,
Log me in instead