This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $polish_notation = "+ 9 * 2 6"; //space seperated polish notation | |
| $invalid_polish_notation = "1 + 2"; | |
| $answer = polish_notation_calculator($polish_notation); | |
| print_r($answer."\n"); | |
| $answer = polish_notation_calculator($invalid_polish_notation); | |
| print_r($answer); | |
| function polish_notation_calculator($polish_notation) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| type entry struct { | |
| ID int `json:"id,omitempty"` | |
| FirstName string `json:"first_name,omitempty"` | |
| LastName string `json:"last_name,omitempty"` | |
| EmailAddress string `json:"email_address,omitempty"` | |
| PhoneNumber string `json:"phone_number,omitempty"` | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TestGetEntries(t *testing.T) { | |
| req, err := http.NewRequest("GET", "/entries", nil) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| rr := httptest.NewRecorder() | |
| handler := http.HandlerFunc(GetEntries) | |
| handler.ServeHTTP(rr, req) | |
| if status := rr.Code; status != http.StatusOK { | |
| t.Errorf("handler returned wrong status code: got %v want %v", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TestGetEntryByID(t *testing.T) { | |
| req, err := http.NewRequest("GET", "/entry", nil) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| q := req.URL.Query() | |
| q.Add("id", "1") | |
| req.URL.RawQuery = q.Encode() | |
| rr := httptest.NewRecorder() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TestGetEntryByIDNotFound(t *testing.T) { | |
| req, err := http.NewRequest("GET", "/entry", nil) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| q := req.URL.Query() | |
| q.Add("id", "123") | |
| req.URL.RawQuery = q.Encode() | |
| rr := httptest.NewRecorder() | |
| handler := http.HandlerFunc(GetEntryByID) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TestCreateEntry(t *testing.T) { | |
| var jsonStr = []byte(`{"id":4,"first_name":"xyz","last_name":"pqr","email_address":"[email protected]","phone_number":"1234567890"}`) | |
| req, err := http.NewRequest("POST", "/entry", bytes.NewBuffer(jsonStr)) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| req.Header.Set("Content-Type", "application/json") | |
| rr := httptest.NewRecorder() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TestEditEntry(t *testing.T) { | |
| var jsonStr = []byte(`{"id":4,"first_name":"xyz change","last_name":"pqr","email_address":"[email protected]","phone_number":"1234567890"}`) | |
| req, err := http.NewRequest("PUT", "/entry", bytes.NewBuffer(jsonStr)) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| req.Header.Set("Content-Type", "application/json") | |
| rr := httptest.NewRecorder() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func TestDeleteEntry(t *testing.T) { | |
| req, err := http.NewRequest("DELETE", "/entry", nil) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| q := req.URL.Query() | |
| q.Add("id", "4") | |
| req.URL.RawQuery = q.Encode() | |
| rr := httptest.NewRecorder() | |
| handler := http.HandlerFunc(DeleteEntry) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "os" | |
| ) | |
| func main() { | |
| type Employee struct { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "os" | |
| "strings" | |
| "testing" | |
| ) |
OlderNewer