Writing tests for the first time for a personal project. Please take a look

I am building a scheme interpreter for my second haskell project. The project has come to a decent stage and I’m currently writing tests using tasty and tasty-hunit. I have never written tests before so I would like to get others opinions on whether I’m testing the right things. Please take a look at my tests: haskeme/test/Spec.hs

As of now, I have written tests for arithmetic operations and list operations such as car, cdr, cons etc. Here’s a code snippet for cdr:

{- (cdr (1 2 3)) => (2 3) (cdr (a b . c)) => (b . c) (cdr (a . c) => c -} cdrT :: TestTree cdrT = testCase "second element from pair" $   do     printVal (cdr [List [Number 1, Number 2, Number 3]]) @?= "(2 3)"     printVal (cdr [DottedList [Atom "a", Atom "b"] (Atom "c")]) @?= "(b . c)"     printVal (cdr [DottedList [Atom "a"] (Atom "c")]) @?= "c" 

Any kind of suggestions/advice are welcome. Thanks in advance πŸ™‚

Make the `diff` command look only for differences from a specified range of lines

Is there a way to make the diff command look only for differences from a specified range of lines (from from line to to line), instead of the entire file? I am having difficulty trying to find the difference between two JavaScript functions in two files that are not on the same line. I could copy the range of lines into a new file, do the same for the other file, then compare them, but it would be tedious to do so especially since the files contain a lot of text.

I tried using:

diff "code1.js" "code2.js" --suppress-common-lines | tee outputFile 

but it obviously does not show only the range of lines I am interested in comparing. It would be also useful if I could specify a range of lines to look for in one file and a different range of lines in the other file.

Look for a clever geometric approach to solve a problem with area.


In the acute $ \triangle ABC$ , the position of each point is as shown, $ F$ is the midpoint of $ BD$ , $ G$ is the midpoint of $ CE$ , $ F$ is not on $ CE$ , and $ G$ is not on $ BD$ . It is known that $ S_{\triangle AFG} = 1$ , and the area of ​​the quadrilateral $ BCDE$ is obtained? enter image description here

An imprecise answer: Considering $ D$ , $ E$ and $ A$ coincide, it is easy to know that the area of ​​the quadrilateral $ BCDE$ is $ 4$ .

Or:Let $ \overrightarrow{AB}=\vec{a}, \overrightarrow{AC}= \vec{b}, \overrightarrow{AE}=\lambda_1 \vec{a}, \overrightarrow{AD}=\lambda_2 \vec{b}, (0 < \lambda_1, \lambda_2<1)$ , then \begin{aligned} S_{\triangle ABC} &= \frac12|\vec{a}\times\vec{b}| \ S_{\triangle AED} &=\frac12 \lambda_1 \lambda_2|\vec{a} \times \vec{b}| \ S_{BCDE} &=S_{\Delta A B C}-S_{\Delta A E D} \ &=\frac{1}{2}\left(1-\lambda_{1} \lambda_{2}\right)|\vec{a} \times \vec{b}| \end{aligned} $ \because$ $ $ \overrightarrow{AF}=\frac{\vec{a}+\lambda \vec{b}}{2} \quad \overrightarrow{A G}=\frac{\lambda_{1} \vec{a}+\vec{b}}{2}$ $

$ \therefore$

\begin{aligned} S_{\Delta A F G} &=\frac{1}{2}\left|\overrightarrow{A F} \times \overrightarrow{A G}\right| \ &=\frac{1}{2}\left|\left(\vec{a}+\lambda_{2} \vec{b}\right) \times\left(\vec{a}_{1} \vec{a}+\vec{b}\right)\right| \ &=\frac{1}{8}\left(1-\lambda_{1} \lambda_{2}\right)|\vec{a} \times \vec{b}| \end{aligned}

$ \therefore$ $ $ \frac{S_{\triangle AFG}}{S_{BCDE}}=\frac{1}{4} \Longrightarrow S_{BCDE}=4$ $

Now, I need a purely geometric approach to solve this problem, but I have no clue. Could anyone help me? Thanks a lot.

Look for better code copy paste from one sheet to another

I wrote this code and it worked well as I want. To look for some values and copy paste the result to another sheet (online for selected column)

I want to know the opinion from this community regarding my code

I just learned the VBA for 1 week. Hope you can share some good advice, thanks πŸ™‚

Option Explicit

Sub Analysis_ClientRating()
Dim lastrow As Long, i As Long, rowppt As Long, colppt As Long Dim rowppt1 As Long, colppt1 As Long, rowppt2 As Long, colppt2 As Long Dim rowppt3 As Long, colppt3 As Long

lastrow = ShNote.Range("C" & Rows.Count).End(xlUp).Row rowppt = ShPPT.Cells(Rows.Count, 1).End(xlUp).Row colppt = ShPPT.Cells(Rows.Count, 1).End(xlUp).Row rowppt1 = ShPPT.Cells(Rows.Count, 1).End(xlUp).Row colppt1 = ShPPT.Cells(Rows.Count, 1).End(xlUp).Row rowppt2 = ShPPT.Cells(Rows.Count, 1).End(xlUp).Row colppt2 = ShPPT.Cells(Rows.Count, 1).End(xlUp).Row rowppt3 = ShPPT.Cells(Rows.Count, 1).End(xlUp).Row colppt3 = ShPPT.Cells(Rows.Count, 1).End(xlUp).Row  Call Entry_Point  For i = 6 To lastrow     Select Case ShNote.Cells(i, 5).Value         Case Is = 20         ShNote.Cells(i, 3).Copy         ShPPT.Cells(rowppt + 6, 3).PasteSpecial xlPasteValues         ShNote.Cells(i, 5).Copy         ShPPT.Cells(colppt + 6, 4).PasteSpecial xlPasteValues         rowppt = rowppt + 1         colppt = colppt + 1          Case Is >= 17         ShNote.Cells(i, 3).Copy         ShPPT.Cells(rowppt1 + 6, 6).PasteSpecial xlPasteValues         ShNote.Cells(i, 5).Copy         ShPPT.Cells(colppt1 + 6, 7).PasteSpecial xlPasteValues         rowppt1 = rowppt1 + 1         colppt1 = colppt1 + 1          Case Is >= 15         ShNote.Cells(i, 3).Copy         ShPPT.Cells(rowppt2 + 6, 9).PasteSpecial xlPasteValues         ShNote.Cells(i, 5).Copy         ShPPT.Cells(colppt2 + 6, 10).PasteSpecial xlPasteValues         rowppt2 = rowppt2 + 1         colppt2 = colppt2 + 1          Case Is >= 11         ShNote.Cells(i, 3).Copy         ShPPT.Cells(rowppt3 + 6, 12).PasteSpecial xlPasteValues         ShNote.Cells(i, 5).Copy         ShPPT.Cells(colppt3 + 6, 13).PasteSpecial xlPasteValues         rowppt3 = rowppt3 + 1         colppt3 = colppt3 + 1     End Select Next i  Call Exit_Point 

End Sub

look for an mp4 file inside a directory and send it to different directory after converting to mp3 in php?

I have a directory called incoming_folder in which there is an mp4 file.

What I want to achieve through php code is to scan a incoming_folder directory, look for an mp4 file and send it to outgoing_folder after converting it into mp3. Technically outgoing_folder should have mp3 version of mp4 from incoming_folder

Tried with the following code although its scanning the incoming_folder directory but no conversion is happening through ffmpeg. Probably ffmpeg not working ?

<?php $  dir    = 'in_folder';  /* Place where mp4 file is present */ $  files1 = scandir($  dir); print_r($  files1);    /* It lists all the files in a directory including mp4 file*/  $  destination = 'out_folder';  /* Place where mp3 file need to be send after conversion from mp4 */  foreach($  files1 as $  f) {   $  parts = pathinfo($  f);    switch($  parts['extension'])   {     case 'mp4' :       system('ffmpeg -i '.$  f.' -map 0:2 -ac 1 '.$  destination.DS. $  parts['filename'].'.mp3', $  result);        if ($  result) {         // Do something with result if you want         // log for example       }       break;      case 'mp3' :       // copy($  f, $  destination. DS . $  parts['filename']. '.' . $  parts['extension']);       copy($  f, $  destination.DS.$  parts['filename'].'.mp3');       break;     } } ?> 

SP Host web look not propagated to chrome control in add-in web

I have a provider hosted add-in which uses chrome control. Previously, if I changed the look of SP host web, that change would propagate to add-in web too and chrome control would update. This is similar to what is mentioned in this article (point# 8)

Now it has stopped working and the look does not change. Any idea what might have changed?

Look for a value that might be in many columns

Say I have a value in $ A, to match to another sheet of the same file. That value (in this case, a student id) might appear in many columns of the other sheet.

In the following example, I am looking for the ID in $ A2, and trying to match it to the value in columns D, F or H (all of the IDs on a work done in groups of three) then get back the grade (column L)

iferror(vlookup($  A2,'ac6'!$  D:$  L,9,false),iferror(vlookup($  A2,'ac6'!$  F:$  L,7,false),iferror(vlookup($  A2,'ac6'!$  H:$  L,5,false),0))) 

Is there a better way? Right now this is cumbersome enough that I feel the need to use a script to generate these formulas

zscore v.s. minmax normalization, why their results look the same

I’m trying to normalize my time series with two different normalization method, minmax and zscore and compare the results. Here is my code:

def scale_raw_data_zscore(raw_data):     scaled_zscore = pd.DataFrame()     idx = 514844     values = raw_data.loc[idx]['d_column'].values     values = values.reshape((len(values), 1))     scaler = StandardScaler()     scaler = scaler.fit(values)     normalized = scaler.transform(values)     normalized = normalized.reshape(normalized.shape[0])     normalized = pd.DataFrame(normalized, index=raw_data.loc[idx].index, columns=raw_data.columns)     scaled_zscore = scaled_zscore.append(normalized)     return scaled_zscore  def scale_raw_data_minmax(raw_data):     scaled_minmax = pd.DataFrame()     idx = 514844     values = raw_data.loc[idx]['d_column'].values     values = values.reshape((len(values), 1))     scaler = MinMaxScaler(feature_range=(0, 1))     scaler = scaler.fit(values)     normalized = scaler.transform(values)     normalized = normalized.reshape(normalized.shape[0])     normalized = pd.DataFrame(normalized, index=raw_data.loc[idx].index, columns=raw_data.columns)     scaled_minmax = scaled_minmax.append(normalized)     return scaled_minmax  def plot_data(raw_data, scaled_zscore, scaled_minmax):     fig = pyplot.figure()     idx = 514844     ax1 = fig.add_subplot(311)      ax2 = fig.add_subplot(312)      ax3 = fig.add_subplot(313)     raw_data.loc[idx].plot(kind='line', x='date', y='d_column', ax=ax1, title='ID: ' + str(idx), legend=False, figsize=(20, 5))     scaled_zscore.reset_index(drop=True).plot(kind='line', y='d_column', ax=ax2, title='zscore', color='green', legend=False, figsize=(20, 5))     scaled_minmax.reset_index(drop=True).plot(kind='line', y='d_column', ax=ax3, title='minmax', color='red', legend=False, figsize=(20, 5))     pyplot.show() 

I’m adding the plot of the results. Why the results of both scaling methods are exactly the same? And why they have a different pattern from the raw data?

enter image description here