Skip to content

Instantly share code, notes, and snippets.

View krishbhanushali's full-sized avatar
🎯
Focusing

Krish Bhanushali krishbhanushali

🎯
Focusing
View GitHub Profile
<?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) {
@krishbhanushali
krishbhanushali / entry.go
Created April 4, 2019 05:00
Entry model
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"`
}
@krishbhanushali
krishbhanushali / get_entries_test.go
Created April 11, 2019 04:58
This Gist gives you the rough idea about how to
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",
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()
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)
func TestCreateEntry(t *testing.T) {
var jsonStr = []byte(`{"id":4,"first_name":"xyz","last_name":"pqr","email_address":"xyz@pqr.com","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()
func TestEditEntry(t *testing.T) {
var jsonStr = []byte(`{"id":4,"first_name":"xyz change","last_name":"pqr","email_address":"xyz@pqr.com","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()
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)
package main
import (
"encoding/json"
"fmt"
"os"
)
func main() {
type Employee struct {
@krishbhanushali
krishbhanushali / benchmarking_test.go
Last active July 19, 2019 22:10
This is a gist about benchmarking Go Marshaling, Unmarshaling, Encoding and Decoding
package main
import (
"encoding/json"
"fmt"
"os"
"strings"
"testing"
)