EXAMPLE 15.2.3

EXAMPLE 15.2.3

Since we are creating a library to handle money, we will first create an interface in &lsquomoney.h&rsquo, an implementation in &lsquomoney.c&rsquo, and a place to store our unit tests, &lsquocheck_money.c&rsquo. We want to integrate these core files into our build system, and will need some additional structure. To manage everything we&rsquoll use Autoconf, Automake, and friends (collectively known as Autotools) for this example. Note that one could do something similar with ordinary Makefiles, or any other build system. It is in the authors&rsquo opinion that it is generally easier to use Autotools than bare Makefiles, and they provide built-in support for running tests.

Note that this is not the place to explain how Autotools works. If you need help understanding what&rsquos going on beyond the explanations here, the best place to start is probably Alexandre Duret-Lutz&rsquos excellent Autotools tutorial.

The examples in this section are part of the Check distribution you don&rsquot need to spend time cutting and pasting or (worse) retyping them. Locate the Check documentation on your system and look in the &lsquo example &rsquo directory. The standard directory for GNU/Linux distributions should be &lsquo /usr/share/doc/check/example &rsquo. This directory contains the final version reached the end of the tutorial. If you want to follow along, create backups of &lsquomoney.h&rsquo, &lsquomoney.c&rsquo, and &lsquocheck_money.c&rsquo, and then delete the originals.

We set up a directory structure as follows:

Note that this is the output of tree , a great directory visualization tool. The top-level & is simple it merely tells Automake how to process sub-directories:

Note that tests comes last, because the code should be testing an already compiled library. & is standard Autoconf boilerplate, as specified by the Autotools tutorial and as suggested by autoscan .

&lsquosrc/ builds &lsquo libmoney &rsquo as a Libtool archive, and links it to an application simply called main . The application&rsquos behavior is not important to this tutorial what&rsquos important is that none of the functions we want to unit test appear in &lsquomain.c&rsquo this probably means that the only function in &lsquomain.c&rsquo should be main() itself. In order to test the whole application, unit testing is not appropriate: you should use a system testing tool like Autotest. If you really want to test main() using Check, rename it to something like _myproject_main() and write a wrapper around it.

The primary build instructions for our unit tests are in &lsquotests/

TESTS tells Automake which test programs to run for make check . Similarly, the check_ prefix in check_PROGRAMS actually comes from Automake it says to build these programs only when make check is run. (Recall that Automake&rsquos check target is the origin of Check&rsquos name.) The check_money test is a program that we will build from &lsquotests/check_money.c&rsquo, linking it against both &lsquosrc/ and the installed & on our system. The appropriate compiler and linker flags for using Check are found in @[email protected] and @[email protected] , values defined by the AM_PATH_CHECK macro.

Now that all this infrastructure is out of the way, we can get on with development. &lsquosrc/money.h&rsquo should only contain standard C header boilerplate:

&lsquosrc/money.c&rsquo should be empty, and &lsquotests/check_money.c&rsquo should only contain an empty main() function:

Create the GNU Build System for the project and then build &lsquomain&rsquo and & as follows:

( autoreconf determines which commands are needed in order for configure to be created or brought up to date. Previously one would use a script called or bootstrap , but that practice is unnecessary now.)

Now build and run the check_money test with make check . If all goes well, make should report that our tests passed. No surprise, because there aren&rsquot any tests to fail. If you have problems, make sure to see Supported Build Systems.

This was tested on the isadora distribution of Linux Mint GNU/Linux in November 2012, using Autoconf 2.65, Automake 1.11.1, and Libtool 2.2.6b. Please report any problems to check-devel AT

Ordering Fractions – Explanation & Examples

Ordering fraction means arranging fractions from the smallest to the largest (ascending order) or largest to smallest (descending order).

There are two common methods of ordering fractions.

Ordering Fractions using Common Denominator

Fractions can be compared and ordered by determining their equivalent fractions with the common denominator. Common denominators are created by using common multiples of the two numbers. For example, 24 is the least common multiple of 8 and 12.

Yet 8 and 12 have several other common multiples however, 24 is the lowest.

Changing Fractions to Decimals and then Ordering

Conversion of fractions to decimals is another method of ordering fractions.

Arrange the following fractions in ascending order.

First convert all the fraction to decimals as shown below:

Since all the fractions have zero in their unit’s digit, compare them by checking the tenths digit.

Now arrange the decimals in descending order.

There the final answer is 4/5, 3/4, 1/2 and 3/8

There are also other methods of ordering fractions, such as calculating their percentages.

For example , we can solve the problem by expressing it as a percentage.


Ordering Fractions from Least to Greatest (h2)

Let’s understand this with the help of examples.

Arrange the following fractions in ascending order:

  • First, identify all the denominators of the fractions. And in this case, the denominators are 2, 3, 12, 6, and 4.
  • Calculate the least common multiple of all the denominators. You look at the L.C.M. of two numbers at a time and check whether the other denominators are factors of the calculated L.C.M.
  • The least common multiple of denominators 2, 3, 12, 6 and 4 is 12
  • The next step is to rewrite each fraction as an equivalent fraction with the denominator 12.

Now that all the fraction shares a common denominator, it is easier to place the fractions in ascending order by comparing their numerators.

By comparing the numerators, the final answer becomes 1/4, 1/2, 7/12, 2/3, 5/6.

More Examples

1.Arrange the following in ascending order:

Find the LCM of 2, 4 which is 4

Since the numerator 4 is remaining in all fractions, order the fraction as follows:

2. Arrange the fractions below in ascending order:

Determine the LCM of 5, 7 and 25 which is 175

Multiply each fraction by the LCM as:

Now arrange the fractions in ascending order as:

3. Order the fraction from the least to the largest.

Find the LCM of 5, 7 and 6 = 210

Now fractions in ascending order = 2/5 < 4/7 < 5/6

4. Order the following fractions in ascending order

Determine the LCM of the denominators as 18.

6/18 < 9/18< 12/18 and thus the fraction in ascending order

5. Order the fractions below from the lowest to the largest.

Start by calculating the LCM of denominators 4, 20 and 25 = 100

Therefore, the fraction from lowest to largest is

6. Order these fractions in ascending order:

Calculate the LCM of the denominators 15, 18 and 10 as 90

And thus, the fractions in ascending order are: 2/15 < 3/18 < 9/10

7. List the following fractions in ascending order

Calculate the LCM of 15, 14 and 12 as 420

448/420 < 450/420 <4 90/4200420 And hence the fractions in ascending order:

8. Order these fractions in ascending order:

Start by calculating the LCM of the denominators 3, 4 and 5 as 60

Now arrange the fractions as:

40/60 < 45/60 < 48/60 And thus, the fractions from the smallest to largest are:

Shareholders are generally taxable on amounts received from a corporation. The purpose of subsection 15(2) is to include in a shareholder's income amounts received from a corporation in the guise of loans or other indebtedness, with specific exceptions provided in the law.

This bulletin discusses the tax implications to a person or partnership who is a shareholder of a corporation, connected with a shareholder of the corporation, or who owns shares of the corporation through a partnership or trust, of a loan or indebtedness from that corporation, a related corporation or a partnership of which that corporation or a related corporation is a member. It comments on the factors that determine whether or not the loan or indebtedness must be included in the income of the debtor and on the timing of such inclusion. It also discusses the deductibility of repayments and the effect of a series of loans and repayments.

Why did God command the genocide of the Canaanites?

In 1 Samuel 15:2-3, God commanded Saul and the Israelites, “This is what the LORD Almighty says: 'I will punish the Amalekites for what they did to Israel when they waylaid them as they came up from Egypt. Now go, attack the Amalekites and totally destroy everything that belongs to them. Do not spare them put to death men and women, children and infants, cattle and sheep, camels and donkeys.'" God ordered similar things when the Israelites were invading the promised land (Deuteronomy 2:34 3:6 20:16-18). Why would God have the Israelites exterminate an entire group of people, women and children included?

This is a difficult issue. We do not fully understand why God would command such a thing, but we trust God that He is just – and we recognize that we are incapable of fully understanding a sovereign, infinite, and eternal God. As we look at difficult issues such as this one, we must remember that God’s ways are higher than our ways and His thoughts are higher than our thoughts (Isaiah 55:9 Romans 11:33-36). We have to be willing to trust God and have faith in Him even when we do not understand His ways.

Unlike us, God knows the future. God knew what the results would be if Israel did not completely eradicate the Amalekites. If Israel did not carry out God’s orders, the Amalekites would come back to trouble the Israelites in the future. Saul claimed to have killed everyone but the Amalekite king Agag (1 Samuel 15:20). Obviously, Saul was lying—just a couple of decades later, there were enough Amalekites to take David and his men’s families captive (1 Samuel 30:1-2). After David and his men attacked the Amalekites and rescued their families, 400 Amalekites escaped. If Saul had fulfilled what God had commanded him, this never would have occurred. Several hundred years later, a descendant of Agag, Haman, tried to have the entire Jewish people exterminated (see the book of Esther). So, Saul’s incomplete obedience almost resulted in Israel’s destruction. God knew this would occur, so He ordered the extermination of the Amalekites ahead of time.

In regard to the Canaanites, God commanded, “In the cities of the nations the LORD your God is giving you as an inheritance, do not leave alive anything that breathes. Completely destroy them — the Hittites, Amorites, Canaanites, Perizzites, Hivites and Jebusites — as the LORD your God has commanded you. Otherwise, they will teach you to follow all the detestable things they do in worshiping their gods, and you will sin against the LORD your God” (Deuteronomy 20:16-18). The Israelites failed in this mission as well, and exactly what God said would happen occurred (Judges 2:1-3 1 Kings 11:5 14:24 2 Kings 16:3-4). God did not order the extermination of these people to be cruel, but to prevent even greater evil from occurring in the future.

Probably the most difficult part of these commands from God is that God ordered the death of children and infants as well. Why would God order the death of innocent children? (1) Children are not innocent (Psalm 51:5 58:3). (2) These children would have likely grown up as adherents to the evil religions and practices of their parents. (3) These children would naturally have grown up resentful of the Israelites and later sought to avenge the “unjust” treatment of their parents.

Again, this answer does not completely deal with all the issues. Our focus should be on trusting God even when we do not understand His ways. We also must remember that God looks at things from an eternal perspective and that His ways are higher than our ways. God is just, righteous, holy, loving, merciful, and gracious. How His attributes work together can be a mystery to us – but that does not mean that He is not who the Bible proclaims Him to be.

What are the bodily discharges mentioned in Leviticus 15, and why did they make a person unclean?

There are four types of bodily discharges mentioned in Leviticus 15, and all four rendered one “unclean” for at least seven days and required sacrifices to be declared “clean” again. The four types of discharge are 1) a chronic male discharge (verses 1&ndash15), 2) emissions of semen (verses 16&ndash18), 3) a woman’s discharge during menstruation (verses 19&ndash24), and 4) a chronic female issue of blood (verses 25&ndash30). The chronic male discharge was most likely due to some kind of venereal disease, so all four bodily discharges have to do with fertility (or periods of infertility) and the proper function of the sexual organs.

The Law does not give a direct reason for the rules concerning bodily discharges, but a verse near the end of Leviticus 15 gives the best hint: “So they will not die in their uncleanness for defiling my dwelling place, which is among them” (Leviticus 15:31). The question naturally arises, why should discharges from sex organs put someone at risk of death for defiling the sanctuary?

The answer is most likely related to the analogy between the “one-flesh relationship” of a man and woman, and the desired relationship between God and His people. The prophets often spoke of idolatry in Israel as “adultery,” in view of the fact that God had chosen Israel as a holy people unto Himself. The rite of circumcision was given to Abraham in Genesis 17. Thus, all the males among God’s people were to be physically marked (on the sexual organ) as set apart for the Lord. Abraham and all his “seed” were to “walk before me faithfully and be blameless” (Genesis 17:1). In light of circumcision as a covenantal sign, an entire chapter devoted to the productivity and proper use of the sexual organs (Leviticus 15) doesn’t seem so out of place.

The very first command to Adam was “be fruitful and increase in number” (Genesis 1:28). After sin entered the world through Adam, Abraham and his miraculous seed were to fulfill Adam’s commission to “be fruitful” as God’s representative on earth (see Genesis 12:2&ndash3). From the beginning, nothing bore greater witness to the God of Creation than the proper means of procreation so, when the Law was given, the children of Israel were instructed to take seriously the proper and productive use of their sexual organs&mdashall four bodily discharges in Leviticus 15 are “markers” of inappropriate or unproductive use of those organs, just as circumcision “marked” one as a “separated” child of God through the seed of Abraham.

During periods of uncleanness (of which the bodily discharges were a sign), sexual activity was unfruitful and least likely to be honoring to God, and so God forbade physical contact, including sexual activity, with the “unclean.” Leviticus 15 also enforced the ongoing awareness among God’s people of their need to remain set apart for Him alone. In times of uncleanness, God’s people were to have an eager desire to return to full productivity for God’s sake among the nations, given that He had made His “dwelling place” among them (verse 31).

The Law’s added requirement of cleansing and sacrifice once the bodily discharges had ended was primarily to express the individual’s re-consecration to God. The cleansed were “betrothed” to God and spiritually “fertile” they were “separated” to God and desired to increase their tribe and thus publish God’s name throughout the whole earth.

Christians are not under the Law (Romans 6:14) and are not bound by the Law’s strict requirements concerning circumcision, bodily discharges, and sexual activity. However, we are still a “sanctified” people in that we are set apart in Christ to be holy&mdashwe are God’s sanctuary now. As such, we are to behave sexually as those “betrothed” to God and honor Him with our bodies (1 Corinthians 6:12&ndash20 Ephesians 5:18&ndash33).

Prime Factorization Calculator

Please provide a integer to find its prime factors as well as a factor tree.

What is a prime number?

Prime numbers are natural numbers (positive whole numbers that sometimes include 0 in certain definitions) that are greater than 1, that cannot be formed by multiplying two smaller numbers. An example of a prime number is 7, since it can only be formed by multiplying the numbers 1 and 7. Other examples include 2, 3, 5, 11, etc.

Numbers that can be formed with two other natural numbers, that are greater than 1, are called composite numbers. Examples of this include numbers like, 4, 6, 9, etc.

Prime numbers are widely used in number theory due to the fundamental theorem of arithmetic. This theorem states that natural numbers greater than 1 are either prime, or can be factored as a product of prime numbers. As an example, the number 60 can be factored into a product of prime numbers as follows:

As can be seen from the example above, there are no composite numbers in the factorization.

What is prime factorization?

Prime factorization is the decomposition of a composite number into a product of prime numbers. There are many factoring algorithms, some more complicated than others.

One method for finding the prime factors of a composite number is trial division. Trial division is one of the more basic algorithms, though it is highly tedious. It involves testing each integer by dividing the composite number in question by the integer, and determining if, and how many times, the integer can divide the number evenly. As a simple example, below is the prime factorization of 820 using trial division:

Since 205 is no longer divisible by 2, test the next integers. 205 cannot be evenly divided by 3. 4 is not a prime number. It can however be divided by 5:

Since 41 is a prime number, this concludes the trial division. Thus:

The products can also be written as:

This is essentially the "brute force" method for determining the prime factors of a number, and though 820 is a simple example, it can get far more tedious very quickly.

Another common way to conduct prime factorization is referred to as prime decomposition, and can involve the use of a factor tree. Creating a factor tree involves breaking up the composite number into factors of the composite number, until all of the numbers are prime. In the example below, the prime factors are found by dividing 820 by a prime factor, 2, then continuing to divide the result until all factors are prime. The example below demonstrates two ways that a factor tree can be created using the number 820:

Thus, it can be seen that the prime factorization of 820, in either case, again is:

While these methods work for smaller numbers (and there are many other algorithms), there is no known algorithm for much larger numbers, and it can take a long period of time for even machines to compute the prime factorizations of larger numbers in 2009, scientists concluded a project using hundreds of machines to factor the 232-digit number, RSA-768, and it took two years.

Run a cron command every 15 minutes

Cron is a time based scheduling service on Linux and Unix computers which allows you to run process at specific times for example once a day, once every hour and so on. This brief post looks at how to run a cron command every 15 minutes.

The crontab format is minute – hour – day of month – month – day of week followed by the command to run. In the examples below the command to run is listed as /path/to/command – substitute this with the actual command you want to run. Any of these minute/hour/etc values can be * which matches any value.

There are two ways to run a cron command every 15 minutes. The first is like this, where each minute is specified:

The above command will run every hour of every day on the hour, and at 15, 30 and 45 minutes past the hour. If you wanted to offset your 15 minute command to run on e.g. the 5th, 20th, 35th and 50th minutes of the hour you could do this instead:

If you are happy with the command running at 0, 15, 30 and 45 then you can simplify the syntax with the second way of running a cron process every 15 minutes like so:

This last example is the exact equivilent of the first example but more succinct.

Before we dive into precision and recall, it is important to review the confusion matrix.

For imbalanced classification problems, the majority class is typically referred to as the negative outcome (e.g. such as “no change” or “negative test result“), and the minority class is typically referred to as the positive outcome (e.g. “change” or “positive test result”).

The confusion matrix provides more insight into not only the performance of a predictive model, but also which classes are being predicted correctly, which incorrectly, and what type of errors are being made.

The simplest confusion matrix is for a two-class classification problem, with negative (class 0) and positive (class 1) classes.

In this type of confusion matrix, each cell in the table has a specific and well-understood name, summarized as follows:

The precision and recall metrics are defined in terms of the cells in the confusion matrix, specifically terms like true positives and false negatives.

Now that we have brushed up on the confusion matrix, let’s take a closer look at the precision metric.

Data Science

Confusion matrix is an important tool in measuring the accuracy of a classification, both binary as well as multi-class classification. Many a times, confusing matrix is really confusing! In this post, I try to use a simple example to illustrate construction and interpretation of confusion matrix.


For simplicity, let us take the case of a yes or no - binary classification problem. We have eight observations. You have built a model to predict the classes. Both actual classes and also the model predicted classes are given below.

For better understanding, I have added the following columns to the table in a separate table below:

From this column, we can calculate the accuracy of the model. Whenever the classes in both actual and predicted classes match, 'yes' was entered in this column. The total 'yes' to total observations was 5/8 (62.5%) which is nothing but the accuracy of this model.

When accuracy is not be useful?

F score

In sklearn, we have the option to calculate fbeta_score. F scores range between 0 and 1 with 1 being the best. The beta value determines the strength of recall versus precision in the F-score. Higher the beta value, higher is favor given to recall over precision. If beta is 0 then f-score considers only precision, while when it is infinity then it considers only the recall. When beta is 1, that is F1 score, equal weights are given to both precision and recall.

In fact, F1 score is the harmonic mean of precision and recall.

    (a value of +1 means perfect prediction, 0 means average random prediction and -1 means inverse prediction).
  • Youden's J statistic (Sensitivity+specificity -1)
  • Receiver Operating Characteristic (ROC) curve: In ROC curve, we plot sensitivity against (1-specificity) for different threshold values. Area under the ROC Curve (AUC) curve is called AUC. Each point on the ROC curve represents a separate confusion matrix. There are many ways to interpret the AUC, but the definition I found easier is this one:

In sklearn, we can calculate AUC value using sklearn.metrics.auc option.

How to get classification report and confusion matrix in sklearn?

Another useful function is classification report. This provides the precision, recall, f1-score and support (number of true instances per label). In the below picture, we can see that there are two rows: yes and no.

In the above example, we have calculated the precision and recall values considering 'Yes'. Here we also have precision and recall values considering 'No'. In case of 'no' class, precision is 'whether predicted No was correct?'. The value is 3/4=0.75. And, recall is 'whether actual no was correctly predicted?'. Here the values is 3/5 = 0.60.

The last row 'avg/total' is the weighted average, weighted according to support. For example, precision is 0.66 which is = ((0.75*5)+(0.50*3))/8. You can also change the way these averages are calculated (more about this).

Watch the video: Volume under a plane in 1st octant (November 2021).